Having jQuery insert defined content
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(' /');
However, after the last link (aka the last li), I want to only add a space (aka  ). I tried doing this, but it didn't get the job done:
$('#nav1 li,#nav2 li').append(' /').filter('#nav1 li:last,#nav2 li:last').append(' ');
Any ideas?
Thanks! Amit
I haven't tried it, but I think something like this should get the work done:
$('#nav1 li,#nav2 li').not(":last").append(' /').end().last().append(' ');
Try:
$('#nav1 li:not(:last),#nav2 li:not(:last)').append(' /');
$('#nav1 li:last,#nav2 li:last').append(' ');
精彩评论