SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A problem with childs and parents ...

    Hi guys ,

    I am stuck with a little problem with JQuery , I want to apply an OnClick event to a parent div and all of its childs except one child, the child has its own Onclick event .

    What happens is that when I click on that specific child , it executes its OnClick event and then executes the parent's event.

    The problem here is that I want the specific child to execute its event only without executing the parent event ...

    that's my code :

    HTML Code:
    $("#parent").click(function()
    {
       // executes the parent's event ......
       // This applies to all childs   ......
     });	 
    
    $("#specific-child").click(function()
    {
       // executes the child's event ......
     });

    And this is the HTML structure :

    HTML Code:
    <div id="parent">
    
       <div> text ....</div>
    
       <div> text ....</div>
    
       <div> text ....</div>
    
       <div> text ....</div>
    
       <div id="specific-child"> specific content over here ...</div>
    
    </div>

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    From the child function, return false and that will prevent the event from travelling up to the parent one.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •