Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Jquery how do you find out the 'eq' of an element of what is being clicked?

Tags:

jquery

When one of the divs inside 'uploadChoice' is clicked, how can I ascertain which one is clicked? Can I return an 'eq' value somehow?

 <div id=uploadChoice>      <div>Text</div>      <div>Image</div<     <div>Text & Image</div> </div>    $("#uploadChoice div").click(function(){     //insert code here! :)    }); 
like image 359
Stephen Avatar asked Jul 27 '09 15:07

Stephen


People also ask

What is eq method in jQuery?

jQuery eq() Method The eq() method returns an element with a specific index number of the selected elements. The index numbers start at 0, so the first element will have the index number 0 (not 1).

How do you find the value of clicked elements?

Another way to get the element we clicked on in the event handler is to get it from the event object which is the first parameter in the event handler function. And the following JavaScript code: const onClick = (event) => { console. log(event.srcElement.id); } window.

What is the difference between eq () and get () methods in jQuery?

eq() returns it as a jQuery object, meaning the DOM element is wrapped in the jQuery wrapper, which means that it accepts jQuery functions. . get() returns an array of raw DOM elements. You may manipulate each of them by accessing its attributes and invoking its functions as you would on a raw DOM element.

What is TD eq in jQuery?

TD #7. TD #8. Apply three different styles to list items to demonstrate that :eq() is designed to select a single element while :nth-child() or :eq() within a looping construct such as . each() can select multiple elements.


1 Answers

$('#uploadChoice div').click(function(event) {   var index = $(this).index(); }); 
like image 96
brianng Avatar answered Oct 08 '22 09:10

brianng