I want to append some text to the title attribute of all elements of a certain class.
Syntax: $("#add-attr"). click(function () { $("#addAttr"). attr("placeholder", "GeeksforGeeks"); });
append() method inserts the specified content as the last child of each element in the jQuery collection (To insert it as the first child, use .
Show activity on this post. The opposite of . append() is . prepend() .
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."); });
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