Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!