0

値を取得して、<span>Expertise discovery</span>次のように href にタイトルを追加し たいと思います。<a href="discovery.html" title="Expertise discovery">

<li class="tooltip-parent">
    <a href="discovery.html">
    <span>
        <img src="discovery.png"/>
    </span>
    </a>
    <div class="tooltip">
        <span>Expertise discovery</span>
    </div>
</li>
4

5 に答える 5

2

次のようなものを試すことができます:

//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); 
于 2013-07-26T07:59:25.613 に答える
1

あなたは次のようなことができます

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

デモ:フィドル

于 2013-07-26T08:00:10.073 に答える
0
$("[href='discovery.html']").attr("title", $(".tooltip > span").text());

また

$(".tooltip-parent > a").attr("title", $(".tooltip > span").text());
于 2013-07-26T08:01:04.687 に答える
0

このコードを使用してください

$('a[href="discovery.html"]').attr("title",$(".tooltip-parent .tooltip").find('span').text(););
于 2013-07-26T08:04:34.803 に答える