A short reminder for those of us writing JS without libraries:
DOM attributes are a little strange from JS. When you iterate over them using the attributes
property, all the names come back completely lower cased. When you fetch them using getAttribute(name)
, the attribute name argument is completely case insensitive.
(Code shown below for anyone that just wants to see it)
<div id="my-id" data-ThisIsInfo="Hello, Internet">
<script type="text/javascript" >
var elem = document.getElementById("my-id");
for (var i = 0; i < elem.attributes.length; i++) {
var attrib = elem.attributes[i];
if (attrib.specified && attrib.name.indexOf("data-") === 0) {
elem.innerText += attrib.name + "='" + attrib.value + "'";
console.log(attrib);
}
}
elem.innerText += elem.getAttribute("data-tHISiSiNFO");
</script>
Debug:
</div>