map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
But this does not work:
map = new google.maps.Map($('#map_canvas'), mapOptions);
I am looking for something like...
$('#map_canvas').toElementBlahblah?
.get(index)
$('#map_canvas').get(0)
$('#map_canvas')[0]
Though, document.getElementById
obviously has better performance - it is the method used internally by the jQuery core when querying the DOM for a single ID selector.
So then you're building a jQuery object just to discard it afterwards. Up to you whether to save some bytes in the bandwidth or microseconds in execution time.
Not much difference, honestly. I use the jQuery version when performance is not concerned and I'm lazy to type document.getElementById
, though vanilla JS is a bit more logical in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With