If you look at doco for the jQuery()
function - it usually looks like an abridged version of $()
- you will see that it accepts several different types and combinations of parameters.
The syntax you asked for is:
$([])
is the jQuery( elementArray )
syntax that allows you to pass an array of DOM elements, where return will be the jQuery object wrapping these elements. By using an empty array, you basically get an empty jQuery object (as if you would pass a selector string that didn't match anything, but without the inefficiency of trying to find a match in the first place).
When the created allFields
contains three DOM elements added to it (where name
, email
and password
are created immediately before as jQuery objects containing each DOM element):
allFields = $( [] ).add( name ).add( email ).add( password )
Presumably the advantage of adding individual elements, rather than just:
allFields = $("#name,#email,#password")
lies in the fact that separate objects for each element are also necessary and would be created in any case, so there is no need to worry about re-selecting them using the query string.
Another perplexity is that I did not notice that allFields
added / added to any / any object, it has only been created and changed, have I missed something?
It is mentioned in two other places in the code:
allFields.removeClass( "ui-state-error" ); // and, later allFields.val( "" ).removeClass( "ui-state-error" );
This is a pretty standard use of jQuery to remove a class or set the value of all elements in a jQuery object. No need to add it to another object.