How to get value of a div using javascript

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

This is my div:

By Color

6条回答
  •  天涯浪人
    2020-11-27 22:09

    DIVs do not have a value property.

    Technically, according to the DTDs, they shouldn't have a value attribute either, but generally you'll want to use .getAttribute() in this case:

    function overlay()
    {
        var cookieValue = document.getElementById('demo').getAttribute('value');
        alert(cookieValue);
    }
    

提交回复
热议问题