Is there any way to add data (that is not a class, id or value) inside the < > selectors of a div?
Say I have something like this
<div class="selection">normal html</div>
That I need to turn into something like this, inserting a data-use-type="STRING" value:
<div class="selection" data-use-type="STRING">normal html</div>
I can’t edit the html directly, so javascript would be the perfect solution for it. And I know how to use the append function, but it does not work for what I want, I think… Can prepend work that way?
2
Answers
Pure JavaScript solution
You can set properties on the
dataset
of the element.