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
JavaScript
x
4
1
if ($(this).parent().next().is('ul')){
2
// code...
3
}
4
I want to achieve this
Pseudo Code:
JavaScript
1
4
1
if ($(this).parent().next().is NOT ('ul')) {
2
//Do this..
3
}
4
Advertisement
Answer
You can use the Logical NOT !
operator:
JavaScript
1
2
1
if (!$(this).parent().next().is('ul')){
2
Or equivalently (see comments below):
JavaScript
1
2
1
if (! ($(this).parent().next().is('ul'))){
2
For more information, see the Logical Operators section of the MDN docs.