document.getElementById not working properly

I have a page that is a template, that I load upon clicking a link.
This page has various tabs in a scrollable tabbar.
One of this tabs has a div with an ID that serves as the div where I want to put a google map on.
Thing is, when I call the method document.getElementById it does not bring any element. But If I call $$(element_id), it does bring it allright.
Does it has to do with the fact that this div is in a template that is loaded?
Im calling this function on pageInit event in the template.

function InitMapClienteUbicacion() 
    var mapOptions = {
        center: new google.maps.LatLng(0, 0),
        zoom: 6,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    var mapeldoc = document.getElementById("mapaRouteToCliente"); //brings null
    var mapel = $$("#mapaRouteToCliente"); //brings element OK
	mapMenuCliente = new google.maps.Map( mapel , mapOptions );

    marker = new google.maps.Marker({
        position: ClienteLatLng, // inicializado cuando entra al page en menu_cliente.js 
		draggable: false

    mapMenuCliente.setCenter( marker.getPosition() );

I don’t understand the problem.
You can make it work with $$(element_id). Why you want to use document.getElementById.?

Seems like google maps api only works passing an element by getElementById function.
Never mind!, I made it work already with that function, thing is, I dont know what was wrong :confused:

Also resource usage. Vanilla JS always faster, less to parse, but smaller apps gains are negligible.

You may be right about template translation/page generation. If loaded into Dom7 and not drawn, the element will not be in “document”. Alternatively, you can try (if it fits your use case) “document.createElement”

1 Like

I think my guesses were right, and you were right to point it, if I click in the tab were the div is before initializing it, it works fine, that was what I changed.

I will think about the document.createElement alternative, but, if I add an element in the document before it was written by Dom7, wouldn’t that element be duplicated?