tags:

views:

41

answers:

1

I want to append some text to the title attribute of all elements of a certain class. This works to replace the text:

$('.theclass').attr("title", "Replaced text.");

It seemed logical that this would do the trick:

$('.theclass').attr("title", $(this).attr("title") + "Appended text.");

But instead I end up with an empty title attribute. Any ideas?

+1  A: 

In that context, $(this) is not the element of $('.theclass'). Maybe you want to use each:

$('.theclass').each(function() {
    $(this).attr("title", $(this).attr("title") + "Appended text.");
});
strager