Solved

jQuery: Remove <p> tags without loosing content

Posted on 2013-06-09
2
363 Views
Last Modified: 2013-06-09
I want to remove my <p> tags without deleting the <a> tags that are inside them.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Demo</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {

 $('p').remove();

});

</script>
<style type="text/css">

p {
margin: 0;
padding: 0;
}

div a {
display: block;
border: 1px solid blue;
margin: 5px;
}

div p a {
display: block;
border: 1px solid red;
margin: 5px;
}

</style>

</head>
<body>

<div>
 <p>
  <a>Hello</a>
  <a>World</a>
 </p>
 <p>
  <a>Testing</a>
 </p>
 <p>
  <a>Example</a>
  <a>123</a>
  <a>abc</a>
 </p>

</div>

</body>
</html>

Open in new window

0
Comment
Question by:hankknight
2 Comments
 
LVL 42

Accepted Solution

by:
David S. earned 500 total points
ID: 39233511
jQuery's unwrap method can do that:
$(document).ready(function() {

 $('p a').unwrap();

});

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 39233512
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sums of coloumns in html/java 15 68
JQuery serialize and unserialize 8 52
Javascript create file issue 4 49
what is the difference between a object and a array 4 27
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

863 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

27 Experts available now in Live!

Get 1:1 Help Now