jquery ordered list index

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

Answers (5)

entropo
entropo

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 lis.

Upvotes: 0

Naveed Ahmad
Naveed Ahmad

Reputation: 3175

Why not?

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

Upvotes: 0

kgiannakakis
kgiannakakis

Reputation: 104188

Try

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

Upvotes: 1

Daff
Daff

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

Winfield Trail
Winfield Trail

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

Related Questions