Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery remove form tag, not content

Tags:

jquery

Hello i need to remove a form tag but non the content:

<form id="form">
<div> not remove this only the form tag</div>

</form>
like image 662
Federico Avatar asked Oct 22 '09 16:10

Federico


People also ask

How to remove elements and content from a jQuery page?

Remove Elements/Content. To remove elements and content, there are mainly two jQuery methods: remove() - Removes the selected element (and its child elements) empty() - Removes the child elements from the selected element.

How to remove the wrapper element of a tag using jQuery?

Sometime you might require to remove the wrapper or parent element, a typical example is removing the anchor tag around the text. With jQuery unwrap () method you can easily remove the wrapper element and keep the inner HTML or text content intact.

How to remove the parent element of a tag using jQuery?

Sometimes you may need to remove the parent element, a typical example is removing the anchor tag around the text. With jQuery’s unwrap () method, you can easily remove the parent element and keep the HTML content or internal text intact. <p>Lorem ipsum dolor sit amet, consectetur adipiscing <a href="#" class="lien">this is a link</a>.

How to remove HTML tags from a variable in jQuery?

You can also strip/remove HTML tags from any variable as well as text () is jQuery function, so the variable needs to be converted into a jQuery object so that text () can be used. Feel free to contact me for any help related to jQuery, I will gladly help you.


2 Answers

$form = $('#form');
$form.replaceWith($form.html());

Should do what you need.

like image 92
Alex Sexton Avatar answered Oct 09 '22 15:10

Alex Sexton


add an id or class to your div

e.g.

<form id="form">
<div class="wrapper"> not remove this only the form tag</div></form>

Then

$(".wrapper").unwrap();
like image 35
Edesa Avatar answered Oct 09 '22 15:10

Edesa