isElement.ts 576 B

12345678910111213141516
  1. export default function isElement(obj: any) {
  2. try {
  3. // Using W3 DOM2 (works for FF, Opera and Chrome)
  4. return obj instanceof HTMLElement;
  5. } catch (e) {
  6. // Browsers not supporting W3 DOM2 don't have HTMLElement and
  7. // an exception is thrown and we end up here. Testing some
  8. // properties that all elements have (works on IE7)
  9. return (
  10. typeof obj === 'object' &&
  11. obj.nodeType === 1 &&
  12. typeof obj.style === 'object' &&
  13. typeof obj.ownerDocument === 'object'
  14. );
  15. }
  16. }