Bug Tracker

Opened 13 years ago

Closed 13 years ago

Last modified 8 years ago

#870 closed enhancement (wontfix)

isElement

Reported by: john Owned by:
Priority: minor Milestone:
Component: core Version:
Keywords: Cc:
Blocked by: Blocking:

Description (last modified by john)

Build a function that can test for isElement, some tests to consider:

window // should fail
document // should fail
document.body
document.body.childNodes // should fail
document.body.firstChild // fail, text node
document.body.firstChild.nextSibling // fail, comment
document.getElementsByTagName("form")[0]
document.getElementsByTagName("form")[0].elements // fail, array
document.getElementsByTagName("object")[0]

Change History (5)

comment:1 Changed 13 years ago by john

Description: modified (diff)

comment:2 Changed 13 years ago by john

Type: bugenhancement

comment:3 Changed 13 years ago by john

Description: modified (diff)
need: Review
Resolution: wontfix
Status: newclosed

comment:4 Changed 8 years ago by anonymous

Why is this "wontfix"? After all there is $.isWindow and $.isXMLDoc. I'd implement it like this: $.isElement = function (e) { return !!(e && e.nodeType === 1); };

comment:5 Changed 8 years ago by dmethvin

If you profile a largeish jQuery app/site, you'll answer your own question. We test for something being a specific DOM nodeType a lot, often in tight loops. Even today you'll see that the cursed .isXMLDoc() comes up near the top of many profiles so we don't want another bottleneck. If we're not going to use it internally then it should be a plugin.

Note: See TracTickets for help on using tickets.