.is() and .not() are not complementary. See: http://docs.jquery.com/Traversing/is#expr
is( expr ) Returns: Boolean Checks the current selection against an expression and returns true, if at least one element of the selection fits the given expression. http://docs.jquery.com/Traversing/not#expr not( expr ) Returns: jQuery Removes elements matching the specified expression from the set of matched elements. The complement to .not() is .filter(). - Richard On Thu, May 28, 2009 at 5:32 AM, Alaa <ala...@gmail.com> wrote: > > hi, > > I wrote a simple code to test the "is" and "not" filters, like this: > > Script: > $("#isDiv> div").click(function (){ > if ($(this).is(":contains('Offenburg')")) { > alert("Offenburg"); > } > > if ($(this).not(":contains('Offenburg')")) { > alert("Not Offenburg"); > } > }); > > Html: > <div id="isDiv"> > <div class="yellow" style="width:75px; height:75px; > marginLeft: > 0in; float:left; background:yellow"></div> > <div style="width:75px; height:75px; marginLeft:0in; > float:left; > background:blue"></div> > <div class="red" style="width:75px; height:75px; > marginLeft:15px; > float:left; background:red"></div> > <div style="width:75px; height:75px; marginLeft:0in; > float:left; > background:orange"><br/><span>Offenburg</span></div> > <div class="brown" style="width:75px; height:75px; > marginLeft:0in; > float:left; background:brown"></div> > </div> > > > "is" works as expected, when I click on the div that contains the word > "div" it shows the alert, and for the other divs no. > > in the same logic, I suppose for "not", that it will do exactly the > opposite, ie, the alert will arise for all divs that do not contain > "offenburg", but when I tries it, the alert appears for all!!! > > > Any help please? >