开发者

prototype js event observation carrying to elements children

开发者 https://www.devze.com 2023-02-03 06:07 出处:网络
I have a html list as the following: <ul> <li id=\"one\"> <ul id=\"sub_ul\"> <li>sth</li>

I have a html list as the following:

<ul>
 <li id="one">
  <ul id="sub_ul">
   <li>sth</li>
   <li>sth2</li>
   <li>sth3</li>
  </ul>
 </li>
</ul>

I observe a click event on "one" in order to SlideUp, SlideDown "sub_ul". The problem is that when the list is open, clicking on any of the sub-elements triggers the Sli开发者_如何学CdeUp action. I would naturally like to avoid this. Could anybody please tell me how I can do that?

Cheers, Manojo


In your event handler first check if an item has been clicked.

$('one').observe('click', function(event)}{
    if (event.findElement('li') != document) {
        event.stop;
        return;
    }

    // continue normal processing
});
0

精彩评论

暂无评论...
验证码 换一张
取 消