Javascript DOM Attribute Get

Description

Javascript DOM Attribute Get

View in separate window


<!DOCTYPE html>
<head>
<title>Recipe</title>
<meta charset="utf-8" />
<script>

window.onload=function() {/*  w  w w .  j  a v  a 2  s .  com*/

// first approach

let targetNode = document.getElementById("target");
if (targetNode.hasAttribute("class")) {
   console.log(targetNode.getAttribute("class"));
}
}
</script>

</head>
<body>
<div id="target" class="target">This is a paragraph in a div element</div>
</body>
</html>



PreviousNext

Related