How can I expand everything, leaving only

How to deploy all parents using jQuery?

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

How can I expand everything, leaving only <a href="link"></a>?

-edit -

Sorry, I had to provide more information. Basically, I'm trying to target all athat are the only child spanthat are surrounded by tags p. I was hoping the following would do the trick, but only expand the tags p. I was wondering if there is a way to remove tags span.

$('p > span:only-child > a:only-child').unwrap();

+2
source share
2 answers

This would do it:

$(document).ready(function() {
    var link = $("a").detach();
    $("p").remove();
    link.appendTo("body");
});

Detaches the link from the DOM and defers it in linkvar. Completely removes pfrom the DOM. Repeats atag binding body.

, , p, body. , , :

<div id="foo">
<p><span><a href="link"></a></span></p>
</div>

:

link.appendTo("#foo");

:

, ( ). .:)

$('p > span:only-child > a:only-child').unwrap().unwrap();
+2

. .

var theLink = $("span").html();
$("p").remove();
$("body").html(theLink);
0

All Articles