Home jquery How to determine in jQuery to the element of its number in...

How to determine in jQuery to the element of its number in the sample?

Author

Date

Category

For example, there is a sample list (Li tags). By clicking on an element (LI), we catch it with this, and then how to find out what element on the account we clicked?


Answer 1, Authority 100%

$ .index ()

var $ set = $ ('ul li');
$ ('UL'). ON ('Click', 'Li', Function () {
  var n = $ set.Index (this);
  Console.log (N);
});

http://jsfiddle.net/oceog/zlzg2/


Answer 2, Authority 14%

$ ('ul'). ON ('Click', 'Li', Function () {
  Alert ($ (this) .INDEX ());
});

http://jsfiddle.net/kbssu/

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions