document.getElementById('menu_link').addEventListener('click', show_menu);
document.getElementById('close_menu').addEventListener('click', hide_menu);
function show_menu () {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange=function()
{
if (xhr.readyState==4)
{
document.getElementById('menu_call').innerHTML = xhr.response;
}
}
xhr.open('GET', "menu.html", false);
xhr.send();
document.getElementById('menu').classList.remove('hidden');
}
Hi Im doing a one page site and trying to load the content using ajax but i have troubles when im trying to use de ids located in the external htmls in my js script. I hope this part of code shows what i mean.
close_menu div is inside menu.html and i can only reach to it if I put
document.getElementById('menu_link').addEventListener('click', show_menu);
inside function show_menu () { ... } after xhr.send() for this specific case I can do it this way but as the web gets more complex it gets messy so I was wondering if i can access to all id loaded using ajax from any part of the js code.
Thanks!