HTML | DOM renameNode() Method
In HTML document, the document.renameNode() method is used to rename the nodes. The nodes which are renamed must be of type Element and Attr.
Syntax:
document.renameNode(node, namespaceURI, nodename)
Parameters: The renameNode() pass node, namespaceURI and nodename as parameters.
- node: The parameter node represents the object user wants to rename.
- namespaceURI: The parameter namespaceURI denotes the namespace URI of the node.
- nodename: This parameter specifies the new nodename.
Return Value: This method returns the node object which represents the renamed node.
Example: The below program fetches the first paragraph of the given HTML script and replace its content with “GeeksForGeeks”. It then renames the first paragraph to <h1>.
<html> <body> <p>hello</p> <button onclick="myFunction()">Rename</button> <script> function myFunction() { var p = document.getElementsByTagName("P")[0] .innerHTML="GeeksForGeeks"; document.renameNode(p, null, "h1"); } </script> </body> </html> |
Output:
Before Pressing Button:

After Pressing Button:

Sopported Browser: The major browsers are not supported by DOM renameNode() Method.
Recommended Posts:
- HTML | DOM contains() Method
- HTML | DOM addEventListener() Method
- HTML | method Attribute
- HTML | DOM importNode() Method
- HTML | DOM insertAdjacentElement() Method
- HTML | DOM normalize() Method
- HTML | DOM getElementsByTagName() Method
- HTML | DOM querySelectorAll() Method
- HTML | DOM hasAttributes() Method
- HTML | DOM querySelector() Method
- HTML | DOM normalizeDocument() Method
- HTML | DOM fullscreenEnabled() Method
- HTML | DOM writeln() Method
- HTML | DOM getElementById() Method
- HTML | DOM Storage key() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



