is HTML DOM element

by 1qazxsw2

HTML

<div>Check the console</div>

CSS

@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400&display=swap');

* {
  font-family: 'Roboto', Arial, sans-serif;
}

JavaScript

function isHTMLDOMElement(obj) {
  if (Object.prototype.toString.call(obj).slice(-8) === 'Element]') {
    if (Object.prototype.toString.call(obj).slice(0, 12) === '[object HTML') {
      return true;
    }
    return false;
  }
  return false;
}

console.log(isHTMLDOMElement(document.querySelector("div")));
console.log(isHTMLDOMElement(document))