开发者

modify all html of a certain class

i have this

<p class="comment_date" title="a">c</p>
&l开发者_高级运维t;p class="comment_date" title="b">b</p>

i want put the title in the html of any element. so i try with this:

$(".comment_date").html($('.comment_date').attr("title"));

But it's wrong

how i can do it?

thanks


$('.comment_date').each(function() {
    $(this).html( $(this).attr('title') );
});

I think this should do it - let me know if that isn't what you're looking for.

It may be worth it to check if the title attribute length is >0. It's best to use .each for cases such as this, otherwise you're setting something to the combined value of multiple elements' values if you don't use .each.


This should do it

$(".comment_date").each(function(i,e) {
  var x = $(e);
  x.html(x.attr("title"));
});


try this:

$(".comment_date").each(function() {
    var cd = $(this);
    cd.html(cd.attr("title"));
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜