How do you check if a JavaScript Object is a DOM Object?

后端 未结 30 2727
-上瘾入骨i
-上瘾入骨i 2020-11-22 16:06

I\'m trying to get:

document.createElement(\'div\')  //=> true
{tagName: \'foobar something\'}  //=> false

In my own scripts, I used

30条回答
  •  深忆病人
    2020-11-22 16:32

    old thread, but here's an updated possibility for ie8 and ff3.5 users:

    function isHTMLElement(o) {
        return (o.constructor.toString().search(/\object HTML.+Element/) > -1);
    }
    

提交回复
热议问题