Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • 41
    This is too much for such a simple thing. see Tim Büthe answer
    – vsync
    Commented Nov 24, 2009 at 9:28
  • 1
    This is the correct answer. The 'length' method has the problem that it gives false positive with any number, for example: $(666).length // returns 1, but it's not a valid selector
    – earnaz
    Commented Sep 16, 2015 at 16:23
  • 4
    This is extremely expensive for very simple task. Just look into jquery implementation if .is() and you will see how much code it needs to process to answer you this simple question. Also it is not obvious what you want to do exactly, so it is same or maybe less elegant then solution in question. Commented Feb 22, 2016 at 19:59