The answer to your IT questions
 

Advanced search  • Search tips
My QUESTIONS & ANSWERS
 Question:

How to disable onClick event

User Asked by: milen
Published on: 09:42/15.02.2008
Status: OPEN
I have embedded div in another div. In the parent DIV element I have placed onClick event but I want to disable that event for the inner DIV. How can I do that?

<div onclick="goToURL()">
    <div>Don't goToURL() on onClick</div>
</div>


 Answers: 1
Sort by: /\ date | rating
Image Answer by: xpert
Posted on: 09:42/15.02.2008
Rating: 2.2 from possible 5 with 8 votes
You can use property "cancelBubble" to stop propagating the event to parent layer. I made sample with two layers with different border. This solution works on IE, FFox, Opera, Safari. don't use "window.event" as this is not recognised by FFox. Here it is :


<html>
<head>

</head>    
<body>
<div onclick="alert('outer');"  style="border:1px solid red;">    
    <div onclick="event.cancelBubble = true; return false;" 
         style="border:1px solid green;margin:10px;">
            Don't goToURL() on onClick
    </div>
</div>
</body>
</html>
Vote:

Please vote! Your opinion matters!
If you haven't found what you've looking for, post a question
  
| Home | Hall of fame | Register | Log in | Terms of service | Help | Contacts |