I am handling a click on a list item with jquery:
$("#some_list li").click(function(event) {
// magic happens here
}
The list items look like:
<li><input type='checkbox'>Some text<span class='info'>(?)</span></li>
I want to have different behaviours depending on whether the user clicks within the (?), or anywhere else in the list. How can I detect which element the user clicked on?
Like
this:All event handlers run in the context of the element, so
thiswill refer to the native DOM object for the element that triggered the event.However, this doesn’t exactly answer your question –
thiswill be the element that the handler was registered for.To find the actual element that was clicked on (which can be a child of
this), you should write$(e.target)