Checking if a Variable has been assigned an Element or a String
I am building a sma开发者_Go百科ll library that involves object manipulation, and there will be an input that might be assigned an ID of an element (which will then use document.getElementById
), or something like document.getElementBy
... and whatever goes here.
Does anyone know how to determine if its a string or an HTML Element
typeof
http://jsfiddle.net/zeF4J/
typeof should work:
typeof variable == "string"
精彩评论