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:

    It sounds to me like you're looking for .stopPropagation(). Calling stopPropagation will prevent the event from "bubbling" up to parent containers.


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