I would like to replicate jquery object selection, for example
When i select multiple objects with
var test = $(".someclass");
I get the object with all selected objects with that class.
Now how could i keep adding objects in that war, something like test.push($(".somediv"));
Also i saw .add( jQuery object ) but it gives me error Cannot call method 'add' of null
when i try to add object to an empty variable
Also how can i create jquery variable with no values and then add them later?
You can use
$()to create an empty jQuery object and then you can use.add()to add more items to it via a selector:When using
.add(), just remember that it returns a NEW jQuery objects that have the new elements added in. It does not modify the original jQuery object. It’s easy to forget that and do:and wonder why nothing is added to
items(this has bit me several times).