How to use DOM Object CreateAttribute in JavaScript

In this article I am going to explain about DOM Object CreateAttribute in JavaScript.
  • 1233

JavaScript Window object CreateAttribute() Method

JavaScript createAttribute() Method use for create an attribute specifics given name. After create attribute its return to attribute to object.

Syntax

document.createAttribute(attribute name)

Example

<html>

<head>

    <script type="text/javascript">

 

        function myfun() {

            var node = document.getElementById("txt");

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

            mm.nodeValue = "Hello friends";

            node.setAttributeNode(mm);

            alert(node.getAttribute("Attribute"));

        }

 

  

    </script>

</head>

<body onload="myfun();">

    <div id="txt">

        <p>

            Some content here</p>

    </div>

</body>

</html>

 

Output


createattribute.gif

 

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
 

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.