hice un script para importar jquery a un sitio web pero por alguna razón no funciona. eso es todo
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();como en este caso, cuando presiona la barra espaciadora, debería alertar con un saludo feliz, pero solo dice que $ id no está definido. ¿Soy tonto o algo así?
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();puedes usar importar
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();