Computer >> Computer tutorials >  >> Programming >> HTML

HTML DOM removeNamedItem() Method


The HTML DOM removeNamedItem() method removes the node specified in its parameter from an attribute node using its name in an HTML document.

Syntax

Following is the syntax −

node.removeNamedItem(node);

Example

Let us see an example of removeNamedItem() method −

<!DOCTYPE html>
<html>
<head>
<style>
   html{
      height:100%;
   }
   body{
      text-align:center;
      color:#fff;
      background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) center/cover no-repeat;
      height:100%;
   }
   .btn{
      background:#0197F6;
      border:none;
      height:2rem;
      border-radius:2px;
      width:60%;
      margin:2rem auto;
      display:block;
      color:#fff;
      outline:none;
      cursor:pointer;
   }
</style>
</head>
<body>
<h1>DOM removeNamedItem() method Demo</h1>
<p style="color:#db133a;font-size:1.2rem;">Hi! I'm a para element in HTML with some random text</p>
<button onclick="remove()" class="btn">Remove Attribute using removeNamedItem() method</button>
<script>
   function remove() {
      var p=document.querySelector("p");
      p.attributes.removeNamedItem("style");
   }
</script>
</body>
</html>

Output

This will produce the following output −

HTML DOM removeNamedItem() Method

Click on “Remove Attribute using removeNamedItem() method” button to remove style attribute from <p> element.

HTML DOM removeNamedItem() Method