7

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?

Joel Cochran
  • 7,139
  • 2
  • 30
  • 43
jurihandl
  • 665
  • 1
  • 9
  • 24

3 Answers3

13

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

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
0

Try:

document.getElementsByTagName("ul")[0].textContent.replace(/\//g,"")
Tamil Selvan C
  • 19,913
  • 12
  • 49
  • 70
Thomas Junk
  • 5,588
  • 2
  • 30
  • 43
0

assign the output to a string called var outPut, then

outPut.replace('/','');

output.replace('a><li','a></li');
Fabrício Matté
  • 69,329
  • 26
  • 129
  • 166
mathew
  • 193
  • 1
  • 5