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

123
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 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