jQuery: how to change tag name?
For example:
<tr> $1 </tr>
I need
<div> $1 </div>
Yes, I can
But can I make it directly?
PS:
$(tr).get(0).tagName = "div";
results in DOMException
.
Choose the Tag you want to rename. Right-click on it and choose Rename to rename the Tag. You can also click on the name of the Tag to rename quickly. Change the name from the colors to anything you like and hit Enter.
To change the element tag name in JavaScript, simply need to make a new element and move over all the elements so you keep onclick handlers and such, and then replace the original thing.
You can replace any HTML markup by using jQuery's .replaceWith()
method.
example: http://jsfiddle.net/JHmaV/
Ref.: .replaceWith
If you want to keep the existing markup, you could use code like this:
$('#target').replaceWith('<newTag>' + $('#target').html() +'</newTag>')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With