views:

22

answers:

2

suppose i have 3 li. what i want to do is when i click any li then i want to know which li was clicked and add an event according to it. how do i do it with jquery, any help or suggestions please

A: 

jQuery will automatically capture the clicked element that you specify in the wrapped set:

$('ul li').click(function(){
  alert('I was clicked, my text is: ' + $(this).text());
});

See the example here.

You need to provide your html markup for exact what you need.

More Readings:

Sarfraz
A: 

In jQuery, within an event handler the this keyword refers to the element which triggered the event.

$('li').click(function() {
  alert($(this).text()); // read out the text of the list item that was clicked
}
thomasrutter