Why does a script work within HTML and not in JS?

Asked

Viewed 332 times

0

I am making use of toggle to change an icone and noticed that the script I made did not work at all, I played it inside html and it worked smoothly, but when I play it back to his js file, where it has several functions that I am using, It just doesn’t work anymore. the script is this:

$("span#orderColumn").click(function(){
    $("span i.i").toggleClass('halflings-triangle-top halflings-triangle-bottom');
});

it is very simple, but it is not working, I have checked the order of loading of Jquery, I have checked if the path is correct, I do not know what else

  • 1

    You are probably referenced to Jquery after your.Js File

  • 1

    Does the file reference you are using is not wrong? In the browser console shows some error message?

  • already looked at it, the jquery is referenced even before, and I also looked if the reference would be wrong, but is pulling normal, the Inspect shows right without any request error

  • Importing the script you created is in the html <head> section?

  • no, I’m leaving it to the end of html before closing the body, so it doesn’t compete with loading css and html,

  • 1

    How you load that file .js external? do it at the end of the body?

  • Try using a.log('before') console and.log('inside') click ;

  • outside he catches, inside no

Show 3 more comments

1 answer

1


Remember to put your.js file after jquery.

Put this code also inside

$(document).ready(function(){

})
  • I already put it, it didn’t work,

Browser other questions tagged

You are not signed in. Login or sign up in order to post.