• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 306
  • Last Modified:

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.
0
Luv2Muff
Asked:
Luv2Muff
1 Solution
 
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
 
mickey159Commented:
save the text into a variable then apply the code.
Get a array to record it and remove the tags.

Good luck!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
edupCommented:
Sorry i didnt read the complete question:

Just one appointment : )

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

Open in new window

0
 
Luv2MuffAuthor Commented:
Works a treat thanks you!!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now