Javascript DOM Attribute Remove

Description

Javascript DOM Attribute Remove

View in separate window

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

window.onload=function() {//  w w  w .j  av  a 2  s  .  co m

// first approach

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

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



PreviousNext

Related