Link to home
Start Free TrialLog in
Avatar of Luv2Muff
Luv2Muff

asked on

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.
Avatar of edup
edup
Flag of Portugal image

Try this:

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

or

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


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

Open in new window

Avatar of Luv2Muff
Luv2Muff

ASKER

Hi, That removes all the text inside the tag
save the text into a variable then apply the code.
Get a array to record it and remove the tags.

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of edup
edup
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Works a treat thanks you!!