How does this differ from filter(':visible').each(function(){...})?
Corey
On Sep 30, 2006, at 3:05 PM, Jörn Zaefferer wrote:
> Hi folks,
>
> the thread about showing and hiding DDs when clicking DTs gave me an
> idea for a chainable if/else construct. I have implemented and
> tested it
> and now I'd like to know if this is useful enough to be released as a
> plugin or even adding to the core.
>
> Basically I extended the current is(String expression) method. It now
> accepts one or two functions. If one is given, it will be executed for
> every element that fits the expression. If the second function is
> given,
> it will be executed for every element that does not fit the
> expression.
>
> Applied to the click dt to show/hide dd example:
> $(document).ready(function() {
> $('#faq').find('dd').hide().end().find('dt').click(function() {
> $(this).next().is(':visible',
> function() { $(this).slideUp(); },
> function() { $(this).slideDown(); }
> );
> });
> });
>
> The extended is method looks like this:
> is: function(expr, ifCallback, elseCallback) {
> if(ifCallback) {
> var elseCalllback = elseCallback || function() {};
> return this.each(function() {
> if($(this).is(expr)) {
> ifCallback.apply(this);
> } else {
> elseCallback.apply(this);
> }
> });
> }
> return expr ? jQuery.filter(expr,this).r.length > 0 : false;
> },
>
> The strength of this addition: is() returns the jQuery object,
> therefore
> it does not break the chain. Your opinions?
>
> -- Jörn
>
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/