Pantelis B Pantelis B - 4 months ago 339x
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") ) {


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.