jquery如何获取值并将其放置在其他位置?

jquery如何获取值并将其放置在其他位置?,jquery,Jquery,我想获取值专业知识发现,并为href添加一个标题,如: 专业知识发现 您可以尝试以下方法: //find the span inside tooltip and get its contents var title = $(".tooltip").find("span").text(); //select the a tag with href set to discovery.html and add the title attribute to it. $('[href="discov

我想获取值
专业知识发现
,并为href添加一个标题,如:

专业知识发现


您可以尝试以下方法:

//find the span inside tooltip and get its contents
var title = $(".tooltip").find("span").text();  
//select the a tag with href set to discovery.html and add the title attribute to it.
$('[href="discovery.html"]').attr("title", title); 

您可以尝试以下方法:

//find the span inside tooltip and get its contents
var title = $(".tooltip").find("span").text();  
//select the a tag with href set to discovery.html and add the title attribute to it.
$('[href="discovery.html"]').attr("title", title); 

你可以这样做

$('.tooltip-parent').each(function(){
    var $this = $(this);
    $this.children('a').attr('title', $this.find('.tooltip span').text())
})

演示:

您可以执行以下操作

$('.tooltip-parent').each(function(){
    var $this = $(this);
    $this.children('a').attr('title', $this.find('.tooltip span').text())
})
演示:

这将对该图像和具有相同标记结构的所有其他图像进行所需的更改

$('.tooltip').each(function(){
    var val = $(this).text(); 
    $(this).parent().find('a').prop('title',val);
});

这将对该图像和具有相同标记结构的所有其他图像进行所需的更改

$('.tooltip').each(function(){
    var val = $(this).text(); 
    $(this).parent().find('a').prop('title',val);
});
使用此代码

$('a[href="discovery.html"]').attr("title",$(".tooltip-parent .tooltip").find('span').text(););
使用此代码

$('a[href="discovery.html"]').attr("title",$(".tooltip-parent .tooltip").find('span').text(););