harnish
harnish

Reputation: 77

jQuery : Removing parent tag not the child of that parent

i am trying to remove parent tag, but removing parent tag should not remove their child element. The child should get attached previous tag

Below is the code:

<div class="mask">
<ul id="TickerT" class="news">
<ul class="tweet_list">
<li class="first odd">
<span class="tweet_time">about 8 minutes ago</a></span>
<span class="tweet_join"></span>
<span class="tweet_text">test test…</a></span>
</li>
</ul>
</ul>
</div>
</div>

There are at-least 5 <li> and now i want to delete <ul class="tweet_list">.
I have tried it with jQuery's replaceWith but no result.

Here's the code i have used from a site
var jj = $("ul.tweet_list").contents()
$(".tweet_list").replaceWith(jj);

But this didn't worked.

What i wanted is i want to remove <ul class="tweet_list"> but not <li> of that <ul>.


Help appreciated, Thanks..

Upvotes: 1

Views: 5112

Answers (4)

SoWhat
SoWhat

Reputation: 5622

var jj = $("ul.tweet_list").html()
$("ul.tweet_list").replaceWith(jj)

There is no content method on jquery. Try the html method.

Upvotes: 0

Didier Ghys
Didier Ghys

Reputation: 30676

Just use the .unwrap() method:

$('.tweet_list').children().unwrap();

DEMO

Upvotes: 2

mas-designs
mas-designs

Reputation: 7556

You could save the .html() content and the parent ul of the list you want to delete into a variable and then add the .html() to the parent ul.

Upvotes: 0

Fr&#233;d&#233;ric Hamidi
Fr&#233;d&#233;ric Hamidi

Reputation: 263147

You can call the unwrap() method on your list item:

$("ul.tweet_list > li").unwrap();

This will remove the .tweet_list <ul> element and reparent the <li> element (and its siblings, if any) under the #TickerT <ul> element.

Upvotes: 5

Related Questions