isElement.ts 603 B

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