Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
195
rated 0 times [  199] [ 4]  / answers: 1 / hits: 166937  / 13 Years ago, wed, july 13, 2011, 12:00:00

For example if I want to do something if parent element for used element hasn't got ul tag as next element, how can I achieve this?


I try some combination of .not() and/or
.is() with no success.


What's the best method for negate code of a if else block?


My Code


if ($(this).parent().next().is('ul')){
// code...
}

I want to achieve this


Pseudo Code:


if ($(this).parent().next().is NOT ('ul')) {
//Do this..
}

More From » jquery

 Answers
20

You can use the Logical NOT ! operator:



if (!$(this).parent().next().is('ul')){


Or equivalently (see comments below):



if (! ($(this).parent().next().is('ul'))){


For more information, see the Logical Operators section of the MDN docs.


[#91197] Tuesday, July 12, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
terrellhunterm

Total Points: 82
Total Questions: 109
Total Answers: 98

Location: Vietnam
Member since Sun, Oct 18, 2020
4 Years ago
;