javascript - Verify if element exists and pass it to function -


i have following:

google.maps.event.adddomlistener(window, 'load', setmap);  function setmap() {   var canvas = document.getelementbyid('map');   // more code } 

i using jquery.

how can check if element "map" exists ...

and call function setmap if exists ...

and pass instead of defining inside setmap function.

try this:

google.maps.event.adddomlistener(window, 'load', setmap);  function setmap() {   var mapelement = $("#map");   if(mapelement.length == 0)   {     return;   }   var canvas = document.getelementbyid('map');   // more code } 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -