Skip to content
Related Articles

Related Articles

HTML | DOM renameNode() Method

View Discussion
Improve Article
Save Article
  • Last Updated : 02 Aug, 2022

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>. 


    <button onclick="myFunction()">Rename</button>
        function myFunction() {
            var p = document.getElementsByTagName("P")[0]
            document.renameNode(p, null, "h1");

Output: Before Pressing Button: After Pressing Button: Supported Browser: The major browsers are not supported by DOM renameNode() Method.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!