brian, I agree that filter() is powerful, but it is not a replacement for hasClass... in fact, as u urself said, it is going to select the elements and create a jquery object for it and it is unnecessary for such a trivial check as hasClass... But is() is a replacement for sure... it returns a boolean as expected, and doesnt select elements or create a jquery object.
For all that matters both approaches work... :) -GTG On 7/11/07, Brian Cherne <[EMAIL PROTECTED]> wrote:
> Mootools: > > includes a hasClass() function: > > > Prototype: > > includes a hasClassName() function: > Someone correct me if I'm wrong, but jQuery does have a "hasClass" method... it's just called "filter" ... and far more powerful because you can use any jQuery expression (not just classes). $('p').filter('.intro')... $('p').filter('.intro:visible')... There is also the opposite "not" method... $('p').not('.intro')... I don't think I'd ever use "hasClass" as long as "filter" was around... unless there were performance benefits to targeting class more specifically with hasClass. I do find myself coding if( $('p')[0] ) sometimes have wondered if there is (or will be) something more explicit (for those unfamiliar with jQuery) but then I usually add a comment '// check to see if element exists' and just move on. Brian.