Get clicked element data with jquery

Sometimes small problem becomes the big trouble for us and that takes our unexpected time.Here i am going to discuss same kind of problem which is common in jquery.In this article, i will show that how we can get clicked element data with jquery.For better explanation let us assume that we have multiple input field buttons in a div.Now we want to get the text of clicked button. Following is the example of html code.


There is a solution to this problem and that is if we put different classes in each input then we can get the data of button according to class like the following code.

Now one problem can occur in this code, if our buttons are in loop then we cannot get the data according to the class because we do not know which button is clicked. Here I have explained the answer of this problem with the following code.

Now, you have seen in this code that i have taken the parent element with current element reference. Note that $(this) element takes the clicked element’s object. Once we get the object then we can get any data of that object.

Download full code