How to find Nth Element , when a click is activated
html, javascript, jquery
Solution
This logs the index of the paragraph that was clicked.
var $elems = $('p');
$elems.on('click', function(e) {
var indexOfElem = $elems.index(this);
console.log("Element with index: " + indexOfElem + " was clicked.");
});
Something like this?
Problem
``` <p>some text</p> <p>some text</p> <p>some text</p> <p>some text</p> <p>some text</p> <p>some text</p> <p>some text</p> ``` Is there any way to identify that when a mouse is clicked at random. Is there anyway to get nth element of the selected through mouse ? edit: when we click over a paragraph, i am using jquery