Hi, > Christof: I appreciate your comments. Even more however I would have > appreciated if you'd have taken into consideration why I made the > proposal.
I did do so, but I think it doesn't help to have functions which have semantically irritating names. If a function is called exists(), that indicates, that the function is operating on one or no element, not a collection (the same problem as with is()). That will make the way to learn jQuery even harder because people don't understand what they are working with. If you are working with a saw, then break() is a senseless operation even when it is often successfully used on flintstones. If people expect the saw to be used like a flintstone, they will fail, even if the saw has an operation break() that tries to guess what a flintstone user is trying to do. It is better to educate flintstone users how to use a saw and what can be done with it. > I just think > that jQuery has gained a lot of it's popularity due to it's > easy-to-learn factor (besides it's superiority and beauty that is : ) > and think this could be a good addition to it. Well, I have not started using jQuery because it is easy to learn, but because it solved some problems for me. I quickly learned that my code can be more elegand and slim when I invested my time to find the best ways of using jQuery. > > <div class="myClass">...</div> > > <div class="myOtherClass">...</div> > > > > $('div').hasClass('myClass'); > > > > What should this return now? > > It should return true. That's because $('a').attr('href') returns the > 'href' attribute of the first anchor matched (afaik). Well, is() returns if there is one element in the collection that fits to the selector. As we see, the semantics is unclear here. I am not really happy with functions like attr() as well. They could also return an array with all values of this attribute in the collection. Then $('a').attr('href')[0] would be the same as the current attr() function. Another thing I dislike about attr() is that attr('name','value') operates on all Elements of the collection while attr('name') doesn't. I think that is irritating. To make that complete I also think, that is() should better return an array of boolean values that indicate for every element in the jQuery object if it fits to the selector. If only one of then is sufficient, then I'd call that function e.g. has(): $.fn.has = function(s) { var r = false; $.each(this.is(s),function(i,n) { r |= n; }); return r; }; Christof