James
James

Reputation: 1706

jQuery hover produces error "Uncaught SyntaxError: missing )"

Can anyone see what the issue here is with this small hover code? or maybe there is a better way of writing it?

Error:

Uncaught SyntaxError: missing ) after argument list

Code:

$('.animated-banner').hover(
        function() {
            $(this' .faded').removeClass('fade-background');
            $(this' .faded').addClass('fade-transparent');
            $(this' .animated').fadeOut();
        }, 
        function() {
            $(this' .faded').removeClass('fade-transparent');
            $(this' .faded').addClass('fade-background');
            $(this' .animated').fadeIn();
        }
    );

Upvotes: 1

Views: 90

Answers (3)

Pepo_rasta
Pepo_rasta

Reputation: 2900

you have invalid selector, $(this expecting end of selctor and therefore ). If you want to choose from $(this) selection only those with some class you have to use additional selecting. Something like

$(this).filter('.faded').removeclass...

or something similar to this

Upvotes: 0

Mark Knol
Mark Knol

Reputation: 10163

You cannot use $(this' .faded'), that is invalid syntax. You could use $('.faded', this) if you want to perform queries from this point.

Upvotes: 1

Dhiraj
Dhiraj

Reputation: 33618

Firstly, concatenation in javascript is using +. Secondly, as Alexander mentioned in the comments, you have to use context with selector like this

$('.faded', this).removeClass('fade-background');

which is same as

$(this).find('.faded').removeClass('fade-background');

Check this answer on SO for more reference

Upvotes: 1

Related Questions