Prevent and stop javascript onclick on child element via stopPropagation and cancelBubble=true - Javascript DOM Event

Javascript examples for DOM Event:onclick

Description

Prevent and stop javascript onclick on child element via stopPropagation and cancelBubble=true

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <script type="text/javascript">
function manualToggle(val)/*from www .j av  a 2  s.c  o m*/
{
    console.log(val.id);
}

      </script> 
      <div id="test" onclick="manualToggle(this);"> 
         <span>Allowed to click</span> 
         <span onclick="event.cancelBubble=true;if (event.stopPropagation) event.stopPropagation();">Not allowed to click</span> 
         <span>Allowed to click</span> 
      </div>  
   </body>
</html>

Related Tutorials