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();
        }
    );
halfer
  • 19,824
  • 17
  • 99
  • 186
James
  • 1,668
  • 19
  • 50
  • 1
    You can not use `this' .faded'`, because you are trying convert DOMelement with string, try change to `$('.faded', this).removeClass('fade-background');` – Oleksandr T. Jul 05 '15 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. – Billy Purvis Jul 05 '15 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. – James Jul 05 '15 at 20:12

3 Answers3

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

Community
  • 1
  • 1
Dhiraj
  • 33,140
  • 10
  • 61
  • 78
1

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

Mark Knol
  • 9,663
  • 3
  • 29
  • 44
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

Pepo_rasta
  • 2,842
  • 12
  • 20