Append text to an attribute rather than replacing it?

后端 未结 3 1082
梦毁少年i
梦毁少年i 2021-02-07 02:01

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

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-07 02:46

    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." });
    

提交回复
热议问题