Solved

Remove a tag but leave the text

Posted on 2010-08-20
7
297 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now