I have some jquery elements:
var elem1 = $("#elem1");
var elem2 = $("#elem2");
var elem3 = $("#elem3");
I need to create a jquery array (list) of these elements, just like having
var allElements = $("#container").children("div");
How can i do this?
Use .add()
method which adds elements to the set of matched elements.
var allElements = elem1.add(elem2).add(elem3);
This worked for me :
var allElements = [];
$("#container > div").each(function(){
allElements.push($(this));
});
1st create the array, then push each div child of your container in this array.
both $("#container > div") and $("#container").children("div") work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With