event handling - Javascript addEventListener not reading resize -
hi i'm trying add eventlistener adds h1 tag width , height of browser when resize it. don't understand why it's not working.
<!doctype html> <html> <head> <title>window size</title> </head> <body> <div id="wh"></div> <script type="text/javascript"> "use strict"; document.addeventlistener("onresize", function(){ var width = document.documentelement.clientwidth; var height = document.documentelement.clientheight; document.getelementbyid('wh').innerhtml = "<h1>width: " + width + " height: " + height + "</h1>"; }); </script> </body> </html>
you have wrong event, needs 'resize'. see here further examples - http://www.w3schools.com/jsref/event_onresize.asp
<!doctype html> <html> <head> <title>window size</title> </head> <body> <div id="wh"></div> <script type="text/javascript"> "use strict"; window.addeventlistener("resize", function(){ var width = document.documentelement.clientwidth; var height = document.documentelement.clientheight; document.getelementbyid('wh').innerhtml = "<h1>width: " + width + " height: " + height + "</h1>"; }); </script> </body> </html>
Comments
Post a Comment