Solved

Remove a tag but leave the text

Posted on 2010-08-20
7
300 Views
Last Modified: 2012-05-10
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
Comment
Question by:Luv2Muff
7 Comments
 
LVL 1

Expert Comment

by:edup
ID: 33485089
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
 

Author Comment

by:Luv2Muff
ID: 33485345
Hi, That removes all the text inside the tag
0
 
LVL 6

Expert Comment

by:mickey159
ID: 33485930
save the text into a variable then apply the code.
Get a array to record it and remove the tags.

Good luck!
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:Luv2Muff
ID: 33486021
Any help with the code for that would be much appreciated :-)
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33486362
Try :
$("p", "#test").each(function() {
   $(this).replaceWith( $(this).html() )
});

Open in new window

0
 
LVL 1

Accepted Solution

by:
edup earned 500 total points
ID: 33486539
Sorry i didnt read the complete question:

Just one appointment : )

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

Open in new window

0
 

Author Closing Comment

by:Luv2Muff
ID: 33486651
Works a treat thanks you!!
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question