How would I update the data-icon attribute in Javascript?
document.getElementById("btn").data-icon = "";
This does not work, as it would for style, or width or whatever.
How would I update the data-icon attribute in Javascript?
document.getElementById("btn").data-icon = "";
This does not work, as it would for style, or width or whatever.
Share Improve this question asked Nov 21, 2013 at 22:14 wazzadaywazzaday 9,6746 gold badges45 silver badges69 bronze badges3 Answers
Reset to default 3Use .setAttribute();
for setting attributes to elements
document.getElementById("btn").setAttribute("data-icon", "");
Also, you cannot use -
when calling objects as it thinks you are trying to subtract, unless you call it like obj['key-name'];
It's an attribute, and for attributes it's setAttribute()
document.getElementById("btn").setAttribute('data-icon', '');
Use .setAttribute();
for setting attributes to elements:
document.getElementById("btn").setAttribute("data-icon", "");
Also, you cannot use -
when calling objects, as it thinks you are trying to subtract, unless you call it like obj['key-name'];
.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745354974a4624060.html
评论列表(0条)