?
Solved

Remove a tag but leave the text

Posted on 2010-08-20
7
Medium Priority
?
304 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 

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 2000 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

Technology Partners: 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!

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

765 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