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
Post a Comment