Skip to content Skip to sidebar Skip to footer

Is It Possible To Have Jquery.click Trigger On The Top Element Only?

I'm trying to make a site where the user can click on any element to edit it's CSS. I use the following to add the click function to all
  • ,
    and
      . $('

    Solution 1:

    You want to stop event propagation, you do this in jQuery by calling the stopPropagation method on the event object.

    $('li,div,ul').click(function (e) {  
        e.stopPropagation();
        alert(this.id); 
    });
    

    Solution 2:

    I believe you'd want to use stopPropagation(); inside the click function.

    Solution 3:

  • Post a Comment for "Is It Possible To Have Jquery.click Trigger On The Top Element Only?"