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());
});
You need to provide your html markup for exact what you need.
More Readings:
Sarfraz
2010-08-09 07:17:42
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
2010-08-09 07:21:53