views:

25

answers:

2

Hi everyone,

I have a navigation menu in xHTML with the following typical structure:

<ul id="nav1">
<li><a href="#">item1</a></li>
</ul>

I have this jQuery script to add a space and a slash after every link:

$('#nav1 li,#nav2 li').append('&nbsp;/');

However, after the last link (aka the last li), I want to only add a space (aka &nbsp). I tried doing this, but it didn't get the job done:

$('#nav1 li,#nav2 li').append('&nbsp;/').filter('#nav1 li:last,#nav2 li:last').append('&nbsp;');

Any ideas?

Thanks! Amit

+1  A: 

Try:

$('#nav1 li:not(:last),#nav2 li:not(:last)').append('&nbsp;/');
$('#nav1 li:last,#nav2 li:last').append('&nbsp;');
Sarfraz
+1  A: 

Hi there Amit,

I haven't tried it, but I think something like this should get the work done:

$('#nav1 li,#nav2 li').not(":last").append('&nbsp;/').end().last().append('&nbsp;');
Karasutengu
Both answers work. Thank you very much!
Amit