How do I prevent a click handler being triggered when a child element is clicked?

Discussion in 'JavaScript' started by lionking, Jun 1, 2011.

  1. #1
    Hi

    I have two div tags, first div is the father and the second div is son Inside the father like this

    
    <div id="father"> 
    <div id="son"> </div>
    </div>
    
    PHP:
    And I've added an event (onclick) in div father like this

    
    <div id="father" onclick="closeFather()"> 
    <div id="son"> </div>
    </div>
    
    PHP:
    My question is why the son inherits the father in the event.

    I want when I click on the Father div implement the event, but when i click on the son does not implement anything because it does not have any event.
     
    lionking, Jun 1, 2011 IP