Javascript function is not loaded with onload, but is with onclick

Asked

Viewed 329 times

0

On the page I’m developing I have this code that starts the menu of the site

<section id="yt_menu" class="block" style="visibility:hidden">

I’m using visibility:Hidden to leave the menu hidden by default, and would like to display it only when the page was loaded, so I changed the tag body for body onload="delayMenu();" but the function is not executed.

Follows function:

function delayMenu() {
    tempoDelay = setTimeout(showM, 2000); // 2 segundos após a página ser carregada
}
function showM() {
    document.getElementById("yt_menu").style.visibility = "visible";
}

I do not know if the problem is in the function, because if change body onload for body onclick works as it should and the menu is displayed.

I’ve also tried to use only body and leave the function like this:

function delayMenu() {
    tempoDelay = setTimeout(showM, 2000); // 2 segundos após a página ser carregada
}
function showM() {
    document.getElementById("yt_menu").style.visibility = "visible";
}
window.onload = delayMenu;

But it didn’t work either. Has anyone ever been through it? Would you know what the problem might be?

The site is running on Joomla, and the first example works on a "clean" page, it just makes no difference when I apply on the site... the Google Chrome console shows no errors.

  • 1

    Your code works as expected. See Fiddle. Better evaluate the rest of your code and supplement the question with more information if you continue to have the problem.

  • @Zuul really, I’m thinking it’s some conflict with the rest of the site, thanks anyway, I’m looking for the solution

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.