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

186
Visualizações
how do i use javascript to import jquery into the head of a document?

i made a script to import jquery into a website but for some reason it doesnt work. this is it

function loadJQuery() {
  let jquery = document.createElement('script');
  let script = document.createElement('script');
  jquery.src = 'https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js';
  jquery.type = 'text/javascript';
  script.innerHTML = `
  //insert jQuery here
  `;
  document.head.appendChild(script);
  document.head.appendChild(jquery);
}
loadJQuery();

like in this case when you pres the spacebar it should alert a happy greeting but it just says that $ id not defined. am i dumb or something

function loadJQuery() {
  let jquery = document.createElement('script');
  let script = document.createElement('script');
  jquery.src = 'https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js';
  jquery.type = 'text/javascript';
  script.innerHTML = `
  $(document).keydown( function(event) {
    if (event.which == 32) {
      alert('hi!ツ');
    }
  });
  `;
  document.head.appendChild(jquery);
  document.head.appendChild(script);
}
loadJQuery();

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

0

you can use import

function loadJQuery() {
import('https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js').then(()=>{
    $(document).keydown( function(event) {
        if (event.which == 32) {
            alert('hi!ツ');
        }
    });
})
}
loadJQuery();

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