With ES6 destructuring you can do
const index = [...el.parentElement.children].indexOf(el)
or
const index = Array.from(el.parentElement.children).indexOf(el)
or ES5 version
var index = Array.prototype.slice.call(el.parentElement.children).indexOf(el)
More Related Contents:
- How to open javascript menu with click & close with mouse out
- How to get children id when I click the parent?
- Change background image php loop [closed]
- Show/hide ‘div’ using JavaScript
- $(document).click() not working correctly on iPhone. jquery [duplicate]
- Uncaught ReferenceError: function is not defined with onclick
- Get the contents of a table row with a button click
- HTML tag want to add both href and onclick working
- Javascript onclick function is called immediately (not when clicked)?
- Onclick event not firing on jsfiddle.net [closed]
- Onclick javascript to make browser go back to previous page?
- Why not always use the index as the key in a vue.js for loop?
- Leaflet- marker click event works fine but methods of the class are undefined in the callback function
- How to completely DISABLE any MOUSE CLICK
- Changing button text onclick
- Javascript – Dynamically assign onclick event in the loop
- addEventListener vs onclick
- CSS Animation onClick
- javascript onclick happening on page load
- Change CSS properties on click
- Redirect form to different URL based on select option element
- How can I stop an onclick event from firing for parent element when child is clicked?
- Change image source with JavaScript
- onclick() and onblur() ordering issue
- Attribute onclick=”function()” not functioning as intended?
- Javascript: Sort array and return an array of indices that indicates the position of the sorted elements with respect to the original elements
- Calling onclick on a radiobutton list using javascript
- Simulating a click in jQuery/JavaScript on a link
- How to track a Google Adwords conversion onclick?
- onclick=”location.href=’link.html'” does not load page in Safari