1

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();
        }
    );
3
  • 1
    You can not use this' .faded', because you are trying convert DOMelement with string, try change to $('.faded', this).removeClass('fade-background'); Commented Jul 5, 2015 at 20:06
  • It's because you're using this' .faded'. I personally don't see why you need to add this seeing as you're already targeting an element. Commented Jul 5, 2015 at 20:08
  • I did try that before but get Uncaught Error: Syntax error, unrecognized expression: [object HTMLDivElement].faded i need to set this and then effect the child class. Commented Jul 5, 2015 at 20:12

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.