in Advanced 

Question preview

HomeQuestion preview:
Log in

How to disable onClick event

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>


Do you know someone who could answer? Ask him for help
Answers: 1
Sort by: date rating
image xpert
11:42/15.02.2008
3.1 from possible 5 with 14 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
Ask question
| Home | Hall of fame | Registration | Log in | Terms of service | Privacy policy | Help | Contacts | RSS |