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


मेरे पास निम्न है:

  google.maps.event.addDomListener (विंडो, लोड ', सेटमैप); फ़ंक्शन सेटमैप () {var कैनवास = दस्तावेज़.getElementById ('मानचित्र'); // अधिक कोड}   

मैं JQuery का उपयोग कर रहा हूँ

कैसे पता लगा सकता है कि तत्व "मानचित्र" मौजूद है ...

और फ़ंक्शन setMap को कॉल करें अगर तभी मौजूद है ...

और setMap फ़ंक्शन के अंदर इसे परिभाषित करने के बजाय इसे भी पास करें।

< p> इसे आज़माएं: <पूर्व> google.maps.event.addDomListener (विंडो, 'लोड', सेटमैप); फ़ंक्शन सेटमैप () {var mapElement = $ ("# map"); अगर (मैप Element.length == 0) {वापसी; } Var कैनवास = document.getElementById ('नक्शा'); // अधिक कोड}

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -