Reputation: 4058
I have a script that creates a list of items with a structure like this:
<li>
<div>Some stuff</div>
<a href="http://www.mysite.com/">New Item</a>
(1 vote)
</li>
I was wondering if there was a way to remove everything outside the <div>
and <a>
tags, in this case the (1 vote) string, with jQuery or regular javascript.
Thanks in advance!
Upvotes: 14
Views: 27792
Reputation: 23
$('li').html($(this).children())
You can try this, it should work. Clean and easy.
Upvotes: 1
Reputation: 6999
$('li').not('div,a').text('')
Try this, untested
Edit
$('li').contents().filter(function(){ return !(this.tagName == 'DIV'
|| this.tagName == 'A');}).remove();
Upvotes: 0