Skip to content
Advertisement

Change div content in HTML5 Custom Data Attributes

I declare a following div in file1.html to draw a nice gauge. The div uses some HTML5 Custom Data Attributes as follow:

JavaScript

Now in Javascript, how do I recall the div and set new number for the “value” attribute and “threshold” attribute? Thanks

Advertisement

Answer

You can use following functions to fulfill your task:

  • element.getAttribute to get the values inside the attribute
  • element.setAttribute to set the values inside the attribute
  • JSON.stringify and JSON.parse to work with JSON

Check the code below.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement