javascript - basic touch gesture not working, using hammer.js -


im beginning learn javascript can implement touch gestures, using hammer.js library, simple piece of code doesnt seem work, know if im missing obvious?

i including hammer.js correctly (have tested putting in path in browser) , have included code in head...

<script type="text/javascript">     var element = document.getelementbyid('tapdiv');     var hammertime = hammer(element).on("tap", function(event) {     alert('hello!');     }); </script> 

and html...

<div id="tapdiv">  <img src="files/tabdiv.jpg" /> </div> 

edit: im receiving error in console hammer.js ...

typeerror: el null [break on error]

if(!css_props || !el.style) {

it appears javascript attempting access object in dom doesn't exist yet -- make sure execute javascript after dom ready:

<script type="text/javascript"> window.addeventlistener('load', function() {      var element = document.getelementbyid('tapdiv');     var hammertime = hammer(element).on("tap", function(event) {         alert('hello!');     })  }, false); </script> 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -