How to use DOM Element SetAttributeNode in JavaScript

In this article I am going to explain about DOM Element setAttributeNode() method in JavaScript.
  • 1786

JavaScript DOM Element setAttributeNode() Method

JavaScript setAttributeNode() method use for set specified attribute node to an element. If attribute already exists on element then then its will replaced it.






    <style type="text/css">



            color: blue;

            font-family: Arial;

            text-decoration: underline;



    <script type="text/javascript">


        function myfun() {

            var mm = document.createAttribute("class");

            mm.nodeValue = "sty";

            var pp = document.getElementsByTagName("H1")[0];








        Hello India</h1>


        click button to set attribute to node</p>

    <button onclick="myfun()">

        chenge it</button>






Before click




After click




You may also want to read these related articles: here
Ask Your Question 
Got a programming related question? You may want to post your question here


More Articles

© 2020 DotNetHeaven. All rights reserved.