views:

387

answers:

4

The following code

stringref = "tab_2";
jQuery('.someclass a:not(.someclass #a_someclass_'+stringref+')').css('color', '#000');

gives me this warning in the FF 3.5.5 error console and I can't figure out why:

Warning: Missing closing ')' in negation pseudo-class '#a_someclass_tab_2'.

Is my syntax failing me or has FF gone bonkers ?

+4  A: 

I think your selector is too complex -- I don't think spaces are allowed within a :not() pseudoclass. Are you trying to match a descendants of .someclass that do not have the given ID? If so, just remove the .someclass within the :not().

Dave
I agree, it works AFAIK, but it is a bit convoluted. I would do it this way: `jQuery('.someclass a').not('#a_someclass_' + stringref + ')').css('color, '#000');`
brianpeiris
quote from the docs "As of jQuery 1.3 :not() also support selectors separated by commas and complex selectors, for example: :not(div a) and :not(div,a)." http://docs.jquery.com/Selectors/not
RamboNo5
Figures, as usually I'm looking for possible issues in the wrong place. That did the trick, Dave :D Much appreciated, thank you !
FreekOne
+2  A: 

I second Dave in that it is most likely the space in your selector.

The :not() syn­tax in jQuery is enhan­ced, com­pa­red to the CSS stan­dard, so it appears that the parser puts out a war­ning since it checks for CSS com­pliance only.

Matthew Vines
Does it really? I don't think anyone else sees an error.
brianpeiris
@brianpeiris It's not actually an error, its a warning. So make sure you have that enabled. There is not actually an issue with his code, it is a false positive picked up by the parser.
Matthew Vines
You're right. I did some digging; jQuery defaults to document.querySelectorAll in FF so running this: `document.querySelectorAll('.someclass a:not(.someclass #a_someclass_tab_2)');` gives you an exception *and* a warning. jQuery then resorts to Sizzle to complete the selection.
brianpeiris
+1  A: 

The syntax looks to be fine, and didn't give me any errors. But I would simplify it a bit, which should help you avoid mis-fired warnings.

var stringref = "tab_2";
jQuery('a.someclass:not(#a_someclass_'+stringref+')').css('color', '#000');
Justin Swartsel
+3  A: 

Firefox (3.5.6) indeed does throw a Warning (if you are not seeing it in Firebug, it's because you do not have 'Show CSS Errors' enabled - see Firebug Console tab).

Firefox is, in a false positive way, parsing the jQuery selector syntax as non-compliant CSS. It is safe to ignore this FF warning (it's not an error remember).

micahwittman

related questions