Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi all

I am trying to close the popup window when i click the outside that popup window i am getting error message like this (0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'addEventListener')


i am using code

C#
document.getElementById("MoadelTest").addEventListener("onclick", function () {
                   alert("hi");
Posted
Comments
JR009 18-Nov-14 0:04am    
Hey, what is MoadelTest? Is it any div?
murkalkiran 18-Nov-14 0:14am    
sorry its a id of div

Hii murkalkiran,
First create overlay div and then popup div and on overlay click event hide both overlay and popup divs.

Check the following fiddle :

http://jsfiddle.net/JRD06/sx0mjwe1/[^]

I hope this will help you.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Nov-14 1:10am    
The solution is wildly excessive and unrelated to the problem. OP almost did it. The solution is way simpler.
Please see Solution 2.
—SA
I tested it, it works, but your sample is has a bug and is incomplete. Compare:
XML
<html><body>

<div id="modelTest">Some div to click on...</div>

<script>
document.getElementById("modelTest").addEventListener("click", function() {
    alert("clicked");
});</script>

</body></html>
Note: "click", not "onclick".

—SA
 
Share this answer
 
v2
Comments
murkalkiran 18-Nov-14 1:39am    
it is not working in IE11 Sergey Alexandrovich
Sergey Alexandrovich Kryukov 18-Nov-14 1:55am    
Really? Hard to believe that...
In all cases, you can write a handler call in the element itself, using the "onclick" attribute on that div.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900