开发者

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('&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


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;');


Try:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜