topherg
topherg

Reputation: 4303

Checking if a Variable has been assigned an Element or a String

I am building a small 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

Upvotes: 0

Views: 45

Answers (2)

Joe
Joe

Reputation: 82634

typeof should work:

typeof variable == "string"

Upvotes: 1

Related Questions