views:

151

answers:

2

The :not always gives me such headache. I am trying to not repeat an addition of plus sign. This is the selector that gives me the element I want:

#submenu li.current_page_ancestor.current_page_parent a:first

Basically I want to say that if that selector does NOT already have a plus in front of it, add it. But where do i put the :not and the various contains? I've tried this, which didn't work:

$j('#submenu li.current_page_ancestor.current_page_parent a:first:not('contains("+")')).prepend("+ ");

thanks so much! (also, if anyone can recommend a way to not use :not, and use ! instead, that would be spectacular!)

A: 

How about:

var el = $j('#submenu li.current_page_ancestor.current_page_parent a:first');
if( el.text().match( /^\+/ ) ) { el.prepend( '+' ); }
thenduks
+1  A: 

try $j('#submenu li.current_page_ancestor.current_page_parent a:first:not(contains("+"))').prepend("+ ");

Chris Gutierrez