How to get index of clicked element?

Nafees Anwar

I have five anchor elements in my navigation. I want to get index of clicked element with jQuery. I tried this code.

$('.navigation ul li a').click(function(e) {

  e.preventDefault();

  var el = $(this).index();
  console.log(el);

 })

But every time I get zero in console.

https://jsfiddle.net/2hg2fkda/ fiddle is here.

Any help will be appreciated. Thanks,

VRK

try this:

$('.navigation ul li').click(function(e) {

  e.preventDefault();

  var el = $(this).index();
  console.log(el);

 })

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get index of clicked element?

From Dev

How to get the index of the clicked array element using JavaScript?

From Dev

Get index and event of the clicked element in knockout

From Dev

MeteorJS: How to get clicked element

From Dev

How to get which element was clicked?

From Dev

How to get position of the clicked element

From Dev

How many elements in the list, the index of the element clicked

From Dev

Change index of clicked element

From Dev

Change index of clicked element

From Dev

How to get the index of the clicked ItemizedIconOverlay in OSM

From Dev

How to get ID of element clicked in Angular?

From Dev

How to get the id of the element that is clicked on the page

From Dev

How to get information from a clicked element with JQuery?

From Dev

How to get the clicked element in Bootstrap collapse event?

From Dev

How to get the clicked element on Ember Component

From Dev

How to get the clicked element's ID

From Dev

.Net How to get the ID of the clicked Element in a Webbrowser

From Dev

How to get what element was clicked by disregarding dom?

From Dev

how to get the element clicked in the listview (Android)

From Dev

How to get the rowIndex of a div element clicked

From Dev

Javascript: indexOf($(this) to get the array-index value of clicked element?

From Dev

when element is clicked get the index and then pass that to trigger another event

From Dev

Get index of element clicked compared to all this type of elements

From Dev

Javascript: indexOf($(this) to get the array-index value of clicked element?

From Dev

Get index of element clicked compared to all this type of elements

From Dev

Ember js get array index of clicked element in an each loop, and filter with it

From Dev

How to get an element by index in ExtJS

From Dev

How to get the "index" of a draggable element?

From Dev

how to get index of element in phpquery

Related Related

  1. 1

    How to get index of clicked element?

  2. 2

    How to get the index of the clicked array element using JavaScript?

  3. 3

    Get index and event of the clicked element in knockout

  4. 4

    MeteorJS: How to get clicked element

  5. 5

    How to get which element was clicked?

  6. 6

    How to get position of the clicked element

  7. 7

    How many elements in the list, the index of the element clicked

  8. 8

    Change index of clicked element

  9. 9

    Change index of clicked element

  10. 10

    How to get the index of the clicked ItemizedIconOverlay in OSM

  11. 11

    How to get ID of element clicked in Angular?

  12. 12

    How to get the id of the element that is clicked on the page

  13. 13

    How to get information from a clicked element with JQuery?

  14. 14

    How to get the clicked element in Bootstrap collapse event?

  15. 15

    How to get the clicked element on Ember Component

  16. 16

    How to get the clicked element's ID

  17. 17

    .Net How to get the ID of the clicked Element in a Webbrowser

  18. 18

    How to get what element was clicked by disregarding dom?

  19. 19

    how to get the element clicked in the listview (Android)

  20. 20

    How to get the rowIndex of a div element clicked

  21. 21

    Javascript: indexOf($(this) to get the array-index value of clicked element?

  22. 22

    when element is clicked get the index and then pass that to trigger another event

  23. 23

    Get index of element clicked compared to all this type of elements

  24. 24

    Javascript: indexOf($(this) to get the array-index value of clicked element?

  25. 25

    Get index of element clicked compared to all this type of elements

  26. 26

    Ember js get array index of clicked element in an each loop, and filter with it

  27. 27

    How to get an element by index in ExtJS

  28. 28

    How to get the "index" of a draggable element?

  29. 29

    how to get index of element in phpquery

HotTag

Archive