Reputation: 1399
I'm building an array with some elements like this :
var listAccordions = [];
$("#accordeon ul.sub-menu.ui-accordion").each(function() {
listAccordions.push("#" + $(this).parent().attr('id') + " ul.sub-menu");
});
everything works fine here, i've got my array and it's nice, now I want to use it like this :
$( listAccordions ).hide();
but this doesn't seem to work ?
Thank you very much for your help
Upvotes: -1
Views: 71
Reputation: 193261
You can do it like this:
$(listAccordions.join(',')).hide();
But the reasonable question: why would you need to have such a data structure?
Upvotes: 1
Reputation: 479
Try something like
$(listAccordions).each(function() {
$(this).hide();
}
Upvotes: 0
Reputation: 177692
$.each(listAccordions,function(i,item) {
$("#"+item).hide();
});
will work. Your array is an array of strings
var listAccordions = [];
$("#accordeon ul.sub-menu.ui-accordion").each(function() {
listAccordions.push($("#" + $(this).parent().attr('id') + " ul.sub-menu"));
});
listAccordions.each(function() {
$(this).hide()
});
should work too
Upvotes: 0
Reputation: 114347
listAccordions
is in memory, not the DOM. You can add a class name to these elements, then use the class name to hide them - if you plan to use this collection for other things. Otherwise, hide them in the loop.
Upvotes: 0
Reputation: 190907
You will have to loop over listAccordions
and call hide
for each one.
for (var i = 0; i < listAccordions.length; i++) {
$(listAccordions[i]).hide();
}
Upvotes: 0