I believe you are picturing a static web page though. In my case, my application is a single page that get's heavily modified on the fly as it is used. I'm adding and removing elements to my page at various times. These elements have their own behaviors that need to be applied. So it is incredibly convenient to me to be able to say $("#myElement").click(...); and not have to worry about if there are any of those particular elements on the page at that time.
If I'd did have to worry about this sort of thing, my code would ballon to be much larger in size simply because I now have to check if something exists before applying a template. Or if I get an empty result (null/undefined) back. So, this one little "over hyped" feature has saved me countless hours of coding and debugging. It may not be of much use to you yourself, but jQuery was coded for a larger audience.. :) I have a rule when it comes to my code - if I have the information available, or I can derive what I need, then that is better than writing a custom routine (or hitting the database again), just to save me a couple of neurons thinking about it. I can quickly derive if any elements exists by checking the length of the jQuery object. That's all I need to know. Granted, for an absolute novice this may be intuitive, but I would suggest that such a novice has other issues than figuring out if an item exists. Rather that sort of novice needs to learn *JavaScript* fundamentals to truly make use of jQuery. Even though jQuery makes things easy, it doesn't mean the lessons that went into those things can be ignored... My thoughts. ( and I'm not trying to be confrontational... honest! :) Shawn McLars wrote: > Yeah, it dawned on me later that the chaining/no error thing was > behind the empty array. I think the no errors bit is overhyped, > though. Other than the $('#id').hide() example, you aren't going to > get very far when a selection fails, and it will make debugging a > little weird if you don't throw an error at some point. I can live > with it. It is the jQuery way. But would it be too much to just put in > an .exists() method like Hamish's in the core? It would add, what, a > dozen bytes, but it would eliminate a lot of these questions and, dare > I say, the code would look better semantically: > > if($('#id').exists()) > > Until then, I think .is() is clearer than .length. To each their own. > Both work, and choice is a good thing.