开发者

jQuery: Insert html from "title" tag into a "span" of a H2 tag

Say I had the following HTML:

<h2>Heading <span></span></h2>

<ul>
<li><a href="#" title="I am wanting to be in H2!">Somethin开发者_如何学编程g</a></li>
<li><a href="#" title="I too am wanting to be in H2!">Something else</a></li>
</ul>

I want to be able to take the title tag from the and place it inside the span of the h2. How can I do so?

Cheers.


$('a').click(function(){
   $('h2 span').html( $(this).attr('title') );
   return false;
});


$("a").each(function(){
  $("h2 span").append($(this).attr("title"));
});


$('h2 span').html($('title').html());

should work :)

i recommend giving the span an unique id, so to call $('#id').ht.... instead

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜