jQuery: The Write Less, Do More JavaScript Library

2 different ways of doing the same thing?

View: New views
5 Messages — Rating Filter:   Alert me  

2 different ways of doing the same thing?

by CoffeeAddict :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Would this not be 2 different ways to do the same thing?

$('input:not(:checkbox));

vs.

$('input').not(:checkbox);

Re: 2 different ways of doing the same thing?

by Cesar Sanz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Did you test your two solutions?
Does the same thing?


----- Original Message -----
From: "expresso" <dschinkel@...>
To: "jQuery (English)" <jquery-en@...>
Sent: Thursday, July 02, 2009 10:11 AM
Subject: [jQuery] 2 different ways of doing the same thing?


>
> Would this not be 2 different ways to do the same thing?
>
> $('input:not(:checkbox));
>
> vs.
>
> $('input').not(:checkbox);

Re: 2 different ways of doing the same thing?

by ricardobeat :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Just like $('div span') == $('div').find('span') and $('div > span')
== $('div').children('span') and so on. Options == good :)

On Jul 2, 1:11 pm, expresso <dschin...@...> wrote:
> Would this not be 2 different ways to do the same thing?
>
> $('input:not(:checkbox));
>
> vs.
>
> $('input').not(:checkbox);

Re: 2 different ways of doing the same thing?

by mkmanning :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Yes and no. The first filters out all inputs that are not checkboxes
before returning the jQuery object.
The second returns all inputs, including checkboxes, and then filters
out those that aren't checkboxes.
The difference is that with the latter, you can operate on the
filtered result, for example adding a css style, and then chain .end()
to revert to the original selection of all inputs and work with them.

On Jul 2, 9:11 am, expresso <dschin...@...> wrote:
> Would this not be 2 different ways to do the same thing?
>
> $('input:not(:checkbox));
>
> vs.
>
> $('input').not(:checkbox);

Re: 2 different ways of doing the same thing?

by mkmanning :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


>Would this not be 2 different ways to do the same thing?

Yes and no.
The first finds all inputs and excludes checkboxes, returning the
result in the jQuery object.
The second finds all inputs and returns them to the jQuery object,
then excludes those that are checkboxes.

WIth the latter, you can chain .end() and revert to the original
selection of all inputs including checkboxes.



On Jul 2, 9:11 am, expresso <dschin...@...> wrote:
> Would this not be 2 different ways to do the same thing?
>
> $('input:not(:checkbox));
>
> vs.
>
> $('input').not(:checkbox);