Remove a tag but leave the text

This is my code:

<div id="test">
   <p>My Text</p>
   <p>My Text</p>
</div>

I need jQuery that will remove all the p tags from#test and just leave:

<div id="test">
   My Text
   My Text
</div>

Thanks in advance.
Luv2MuffAsked:
Who is Participating?
 
edupConnect With a Mentor Commented:
Sorry i didnt read the complete question:

Just one appointment : )

$("p", "#test").each(function() {
   $(this).replaceWith( $(this).html()+"<br>" );
});

Open in new window

0
 
edupCommented:
Try this:

$("#teste p").remove();

or

$("#teste").children("p").each(function(){
  $(this).remove();
});


$("#teste").children("p").each(function(){
  $(this).remove();
});

Open in new window

0
 
Luv2MuffAuthor Commented:
Hi, That removes all the text inside the tag
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
mickey159Commented:
save the text into a variable then apply the code.
Get a array to record it and remove the tags.

Good luck!
0
 
Luv2MuffAuthor Commented:
Any help with the code for that would be much appreciated :-)
0
 
leakim971PluritechnicianCommented:
Try :
$("p", "#test").each(function() {
   $(this).replaceWith( $(this).html() )
});

Open in new window

0
 
Luv2MuffAuthor Commented:
Works a treat thanks you!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.