Skip to content
Advertisement

jQuery: how to change tag name?

jQuery: how to change tag name?

For example:

JavaScript

I need

JavaScript

Yes, I can

  1. Create DOM element <div>
  2. Copy tr content to div
  3. Remove tr from dom

But can I make it directly?

PS:

JavaScript

results in DOMException.

Advertisement

Answer

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:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement