i have this
<p class="comment_date" title="a">c</p>
<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
HTML elements can belong to more than one class. To define multiple classes, separate the class names with a space, e.g. <div class="city main">. The element will be styled according to all the classes specified.
Attribute Values To specify multiple classes, separate the class names with a space, e.g. <span class="left important">. This allows you to combine several CSS classes for one HTML element.
Any number of elements may be assigned the same class name or names. Multiple class names must be separated by white space characters. Yes, just put a space between them.
$('.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"));
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With