Append text to an attribute rather than replacing it?
I know this question is 7 years old. Just in case someone came across this question, here's the solution without using .each:
$('.theclass').attr("title", function() { return $(this).attr("title") + "Appended text." });
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.");
});