Reputation: 11618
Is it possible to add a click event to the numbered index of an ordered list with jQuery? How?
Thanks
/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
Upvotes: -1
Views: 863
Reputation: 2481
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 li
s.
Upvotes: 0
Reputation: 44215
Look at the :nth-child() selector to attach the event handler. E.g.
var index = 2;
$("ul li:nth-child(" + index + ")").click(function() {
// ...
});
Upvotes: 1
Reputation: 5695
$('#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.
Upvotes: 1