vendredi 29 septembre 2017

What is the correct approach to use if in this situation?

I didn't find an answer that satisfies me about this newbie javascript (using jQuery) question...

I have these 2 codes inside a document ready...

CODE 1

$('myElement').click(function(){
     if(isMobile()){
         //do something...
     }
});

CODE 2

if(isMobile()){
    $('myElement').click(function(){
       // do somthing...
    });
}

What is the correct approach and why?

Thanks guys

Aucun commentaire:

Enregistrer un commentaire