Asked 3 years ago
11 Feb 2021
Views 1083

posted

how to rename element in javascript ?

i have some element which i need to rename after load of the complete page ?

so how can i rename the element in javascript like p tag or span tag etc ?
Mahesh Radadiya

Mahesh Radadiya
answered Nov 30 '-1 00:00

you can use document.renameNode , but it not supported most of browser .

how to use document.renameNode ?


document.renameNode(node object, namespaceURI, new nodename);


suppose you want to rename the span html element

var span = document.getElementsByTagName("span")[0];
document.renameNode(span, null, p);

it will rename the node span to p tag

but it not support any browser
in Chrome , you will get error as below :
Uncaught TypeError: document.renameNode is not a function
in firefox ,
TypeError: document.renameNode is not a function

shabi

shabi
answered Nov 30 '-1 00:00

The renameNode() function renames nodes of type Element and Attr.
Chrome - Not Supported
Internet Explorer / Edge - Not Supported
Firefox - Not Supported
Safari - Not Supported
Opera - Not Supported

Why created renameNode() function when it not used in any of best browser ?
we can call renameNode() as useless function.
Post Answer