Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove text between two elements with jQuery

So I got the following html:

<ul>
   <li><a href="#">test</a></li>
   /
   <li><a href="#">test</a></li>
   /
   <li><a href="#">test</a></li>
   /
   <li><a href="#">test</a></li>
<ul>

Sadly this is generated by a Plone extension which was forked and I don't have the possibility to change the output. The list will have a different amount of elements on different pages.

All I need to do is remove the slashed between the list elements. I couldn't come up with a good solution till now.

Is there a simple an powerful solution to do this with Javascript or jQuery?

like image 355
jurihandl Avatar asked May 16 '13 08:05

jurihandl


1 Answers

Use .contents() and .filter() to filter out all the next nodes (nodeType == 3) then remove them using .remove()

$('ul').contents().filter(function(){
    return this.nodeType == 3
}).remove()

Demo: Fiddle

like image 91
Arun P Johny Avatar answered Nov 06 '22 04:11

Arun P Johny