How to get value of a div using javascript

前端 未结 6 2133
情歌与酒
情歌与酒 2020-11-27 21:47

This is my div:

By Color

6条回答
  •  一向
    一向 (楼主)
    2020-11-27 22:24

    First of all

    that is not valid HTML. Read up on custom data attributes or use the following instead:

    Since "data-value" is an attribute, you have to use the getAttribute function to retrieve its value.

    var cookieValue = document.getElementById("demo").getAttribute("data-value"); 
    

提交回复
热议问题