javascript - Change text of all elements with specific data-attribute -
I am currently trying to use jQuery to replace the text of several elements in the value of a specific data-attribute I am
For example:
index.html ---------- & lt; H1 data-change = "text2" & gt; Text 1 & lt; / H1> & Lt; p Data-Change = "Paragraph 2" & gt; Paragraph 1 & lt; / P & gt; I want to convert 'text1' to 'text2' and 'paragraph 1' as 'paragraph 2' (the value of the data-change of that particular element).
How do I do this?
I think I will be able to 'select' all the elements with the data-attribute 'data-change' and then just a simple $ (this) .text ($ (this ) .data ('change')); or something else
You can do this:
$ ('[data] -Change]'). Each (function () {$ (this) .text ($ (this). Data ('change'));}); You can iterate over the elements and change its text.
Comments
Post a Comment