Pantelis B Pantelis B - 1 year ago 664
jQuery Question

Invalid or unexpected token running jQuery to console

I try to do this with jQuery:

I have an id with a specific class. When scrolling this class changes to another class. So, i need to check if this id has the specific class then to add class to another id.

This is what i tried directly through Console of Chrome but i get Uncaught SyntaxError: Invalid or unexpected token.

if(jQuery(#header).hasClass("affix") ) {

Answer Source

That's an invalid syntax. You need to add quotes around the selectors, as they are strings. Change it this way:

if (jQuery("#header").hasClass("affix")) {

The #header and #logo should be strings.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download