jquery: test whether input variable is dom element -


i write jquery function accepts either dom element or id input:

function myfunction(myinput){  // pseudocode:  // if (myinput dom element){  //   var myid = $(myinput).attr('id');  // } else {  //   var myid = myinput;  // }   // stuff myid ...  } 

question: how can tell whether myinput dom element???

it's easier check other way around - check if it's string if use id else treat dom node/element , handle if one.

function myfunction(myinput) {      var myid;      if (typeof myinput == 'string'){         myid = myinput;     } else {         myid = myinput.id; // myinput.id enough     }      //  } 

or if want check against if it's htmlelement every dom html element extends htmlelement abstract interface. check mdc more info on htmlelement.

    ...      if (myinput instanceof htmlelement){         myid = myinput.id; // myinput.id enough     } else {         myid = myinput;     }      ... 

in end won't matter... call!

tom


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -