How to negate code in “if” statement block in JavaScript -JQuery like 'if not then..'

后端 未结 2 1689
花落未央
花落未央 2020-12-09 01:49

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 t

相关标签:
2条回答
  • 2020-12-09 02:08

    Try negation operator ! before $(this):

    if (!$(this).parent().next().is('ul')){
    
    0 讨论(0)
  • 2020-12-09 02:09

    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.

    0 讨论(0)
提交回复
热议问题