Expected Result: +...">

How to break p tags using jQuery?

<p>
     <a href="link"><img src="image"></a>
</p>

Expected Result: <a href="link"><img src="image"></a>

+3
source share
6 answers

You can use replaceWith()to replace the element with your content:

$('p').replaceWith
(
    function() { return $(this).contents(); }
);

See here .

+12
source

You can also use unwrap():

$("p").contents().unwrap();

JsFiddle example

+3
source

For a specific item, Pyou can just go

$('p').html();
0
source

Sort of:

$("p").each(function(){
    var content = $(this).html();
    $(this).parent().append(content);
    $(this).remove();
});

Searches for all p-tags, gets content. Adds it to the parent element and removes the p tag. It does not work in all cases (for example, if P tags should be at the beginning of the parent element.)

0
source

Give an identifier to your p tag

<p id='id'>
     <a href="link"><img src="image"></a>
</p>

then use jQuery to select the internal HTML

$('#id').html();
0
source

specify identifier.

<p id="test">

<a href="link"></a>

</p>

then use

var link = $("#test")[0] ; 
0
source

All Articles