开发者

modify all html of a certain class

开发者 https://www.devze.com 2022-12-12 06:12 出处:网络
i have this <p class=\"comment_date\" title=\"a\">c</p> &l开发者_高级运维t;p class=\"comment_date\" title=\"b\">b</p>

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

精彩评论

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