c

b

I want to put t...">

Change all html of a specific class

I have it

<p class="comment_date" title="a">c</p> <p class="comment_date" title="b">b</p> 

I want to put the title in the html of any element. so I try:

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

But this is wrong

How can i do this?

thanks

+4
source share
3 answers
 $('.comment_date').each(function() { $(this).html( $(this).attr('title') ); }); 

I think this should do it - let me know if this is not what you are looking for.

It might be worth checking to see if the length of the title attribute matches >0 . It is best to use .each for such cases, otherwise you set something to the combined value of the values ​​of several elements if you do not use .each .

+16
source

It should do it

 $(".comment_date").each(function(i,e) { var x = $(e); x.html(x.attr("title")); }); 
+2
source
 try this: $(".comment_date").each(function() { var cd = $(this); cd.html(cd.attr("title")); }); 
0
source

All Articles