I have next html:
<span data-typeId="123" data-type="topic" data-points="-1" data-important="true" id="the-span"></span>
Is it possible to get the attributes that beginning with data-
, and use it in the JavaScript code like code below? For now I get null
as result.
document.getElementById("the-span").addEventListener("click", function(){
var json = JSON.stringify({
id: parseInt(this.typeId),
subject: this.datatype,
points: parseInt(this.points),
user: "H. Pauwelyn"
});
});
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…