1

If I have two variables

var foo = document.getElementById('myDiv');
var foo2 = document.getElementsByClassName('divCollection');

How can I check if a variable is an element, and how can I check if it is an HTMLcollection?

I tried using typeof myVar, but both variables return an object.

Horay
  • 1,388
  • 2
  • 19
  • 36
  • http://stackoverflow.com/questions/7238177/how-to-detect-htmlcollection-nodelist-in-javascript – Pranav C Balan Nov 07 '16 at 04:23
  • @PranavCBalan If I want to check if it's an element, I should do what this answer says: http://stackoverflow.com/a/384380/5244870 And if I want to check if it's an HTMLCollection, I should do what you posted? – Horay Nov 07 '16 at 05:01

0 Answers0