changing the data-icon in pure javascript - Stack Overflow

How would I update the data-icon attribute in Javascript?document.getElementById("btn").data-

How would I update the data-icon attribute in Javascript?

document.getElementById("btn").data-icon = "&#xe082";

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 = "&#xe082";

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 badges
Add a ment  | 

3 Answers 3

Reset to default 3

Use .setAttribute(); for setting attributes to elements

document.getElementById("btn").setAttribute("data-icon", "&#xe082");

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', '&#xe082');

Use .setAttribute(); for setting attributes to elements:

document.getElementById("btn").setAttribute("data-icon", "&#xe082");

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

相关推荐

  • changing the data-icon in pure javascript - Stack Overflow

    How would I update the data-icon attribute in Javascript?document.getElementById("btn").data-

    20小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信