Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
jQuery code in between the page but jQuery library in footer

I have jQuery library in the footer to follow the good practices. It's placed right before the </body> tag. However, I have jQuery sortable code in the middle of the page inside a modal for some reason to sort photos. My sortable code was working this way few months back up to Oct, 2021. However, I did not look up on that part of module for some months and today it's not working. The console is returning this error:

Uncaught ReferenceError: $ is not defined

Example of my code:

<head>
  <title>My First page</title>
</head>

<body>
  <div class="sortPhotos">
    <ul id="sortable" class="reorder-gallery mt-3"></ul>
    <script>
      $(function() {
        $("#sortable").sortable({
          // CODE GOES HERE
        }).disableSelection();
      });
    </script>
  </div>
  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</body>

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

jQuery script elements are usually put in the head element before the body

check here to see exactly where to place the jQuery script tag

about 4 years ago · Juan Pablo Isaza Denunciar

0

It's a good practice to keep the right order when you are running any old javascript projects because the first script run sooner:

<!DOCTYPE html>
 <html>
  <head>
   <title>My First page</title>
  </head>
  <body>
   <div class="sortPhotos">
    <ul id="sortable" class="reorder-gallery mt-3"></ul>
   </div>
   <script src="js/jquery.min.js"></script>
   <script>
    $(function() {
      $("#sortable").sortable({
        // CODE GOES HERE
      }).disableSelection();
    });
   </script>   
  </body>
 </html>

Also check your jquery path.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Order matters.

In your first <script> you try to call the $ function and it errors because $ isn't defined.

In your second <script> you load jQuery which defines $, but by then it is too late.

Reverse the order of your <script> elements.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda