mercredi 6 septembre 2017

JavaScript - If statement in if statement condition

I want to check for an element's existence in the if statement condition, and if so then use the element as part of the comparison. Something like this:

if( if($(".element").length > 0) { $.contains( $(".element")[0], $("[ele]")[0] )} ) {...

I know I could just nest if statements, like:

if($(".element").length > 0) {
    if($.contains( $(".element")[0], $("[ele]")[0] )) {....

But is there a shorter way to do this? Can if statements be used in another if statement's condition like this in some way?

Aucun commentaire:

Enregistrer un commentaire