Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

292
Visualizações
jQuery $(window).on("load", function() only launches after refresh

I had some scripts running on 1.7.1 jQuery and now I am on Wordpress's 1.12.4. The code wouldn't run. I had two errors running:

Uncaught TypeError: $ is not a function https://grumans.ca/delicatessen/:1734

This line on the page is $(window).load(function(){Grumans.deli.init();});

and this

Uncaught TypeError: $ is not a function https://grumans.ca/js/script.js:1162

$(window).load(function(){

     //Grumans.deli.init();
});

I found what I thought was a solution. Someone had posted for a different article that you could do this.

jQuery(function($) {
    $(window).on("load", function() {
       Grumans.deli.init();
    });
});

This got rid of both errors when applied to the page and in the script code, and let my code run, but only if I refresh the page twice. When I first hit the page nothing happens. I am not a code writer. Does anyone know why and how to fix the code so that it runs as soon as the page loads?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

It's hard to know exactly what is going on in your particular case without also seeing the html, but given what you've presented, this might work:


jQuery(window).load(function(){
    console.log('called on page load');
});

The reason your first example doesn't work is because the $ variable hasn't been attached to the window object. It looks like you do have access to jQuery though, which is another global that jQuery attaches to window that is an alias of $.

about 4 years ago · Juan Pablo Isaza Relatório

0

You are using a version of JQuery that doesn't define $ by default like the older versions did. You can just replace $ with JQuery if you really want the load event, but typically DOMReady is a more useful event. Some of the images may not have completely downloaded at that point, but you can usually run any other functions that manipulate the DOM.

The code you put in runs on DOMReady, which means the Load handler isn't installed until then and it may be too late by then.

jQuery(function($) {
   Grumans.deli.init();
});

The above should run the Grumans code every time the page loads, but it does so on DOMReady event.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda