What if instead of plugging in onclick="bob()" to the ul, you go the
unobtrusive route?
This example I'll use apply and id to the ul. You could use a class
but will have to 'grab' or 'target' it differently with $ or $$
functions. Be sure to check for bubbling..
HTML:
<ul id="click_list">
<li>Element 1</li>
<li>Element 2</li>
</ul>
JS:
// get element by Id click_list and set var
var ul_el = $('click_list');
// Function you want to run on click event
var ulOnClick = function(e){
e.stop();
//e.target gives you the element you clicked.
return e.target;
}
// Add the click event to the ul element
ul_el.addEvent('click',ulOnClick);
On Jan 7, 1:25 pm, "Itay Moav" <[email protected]> wrote:
> Greetings
>
> I need to capture the Event object when using the onclick attribute, to find
> out what was the element that was clicked upon.
> my html is:
> <ul onclick="bob()">
> <li>ddfdf</li>
> <li>dfsaff</li>
> ....
> ....
> ....
> </ul>
>
> If there is another way to find out which LI was clicked?
> I can't put the onclick event in the LI level.