Reputation: 43
<p>
<a href="link"><img src="image"></a>
</p>
Expected result: <a href="link"><img src="image"></a>
Upvotes: 3
Views: 2806
Reputation: 484
give an id to it.
<p id="test">
<a href="link"></a>
</p>
then use
var link = $("#test")[0] ;
Upvotes: 0
Reputation: 11866
You can use replaceWith()
to replace an element with its contents:
$('p').replaceWith
(
function() { return $(this).contents(); }
);
See here.
Upvotes: 12
Reputation: 21366
Give an Id to your p tag
<p id='id'>
<a href="link"><img src="image"></a>
</p>
then use Jquery to select inner HTML
$('#id').html();
Upvotes: 0
Reputation: 4371
Something like:
$("p").each(function(){
var content = $(this).html();
$(this).parent().append(content);
$(this).remove();
});
searches all p-tags, gets content. Appends it to the parent element and removes the p tag. Does not work in all cases (for example if the P tags should be at the start of the parent element.)
Upvotes: 0
Reputation: 14747
For a particular P
element, you can just go
$('p').html();
Upvotes: 0