开发者

jquery ordered list index

Is it possible to add a click event to the numbered index of an ordered list with jQuery? How?

Thanks

开发者_如何学C

/edit/ well, maybe i wasn't clear enough, but i did specified that the event would have to be on the INDEX and not on the LI itself. I already have events attached to the LI, i want to know if there is a way to manipulate just the index.

Thanks


$('#targetid').click(function(){'EVENT STUFF HERE'});

should do the trick, though if you're asking how to make the numbers in the list clickable your best bet would probably be to use CSS to extend a transparent DIV wrapped in an A tag back to the left and over the number. Something like

margin-left: -30px; padding-left: 30px;

should let you do that without mucking up your list contents too bad.


Look at the :nth-child() selector to attach the event handler. E.g.

var index = 2;
$("ul li:nth-child(" + index + ")").click(function() {
    // ...
});


Try

$("ol li:eq(n)").click(function () {});


Why not?

$("ol li").click(function(e){});


Check this out for how you can efficiently manage hovers with a class toggle: http://pastie.org/805428

With that pattern you can just manage hiding of elements within your lis.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜