如何从'.each循环'内部创建一个数组并在循环外部使用它?如何使用.jach循环与jQuery创建数组
我.each loop
:
// Loop through all but button with class .apply
$('.profile-nav ul li a').not('.apply').each(function() {
// if currently loop through element has .cur class
if($(this).hasClass('cur')) {
//Get the first class of the match element
var ClassesToApply = $(this).prop('class').split(' ')[0];
}
//How can I create an array from all ClassesToApply?
//var arr = jQuery.makeArray(ClassesToApply);
// This will create an array, but with one element only
});
我怎么能创造所有var = ClassesToApply
一个数组?
而且我该怎么做这个数组呢? 如
$(allClasses from an array as a selectors).doStuff();
你会得到一个字符串数组。你想用这样一个数组做什么? jQuery方法在包含DOM元素的数组上执行,而不是字符串。 –
我正在寻找使用字符串作为选择器来显示/隐藏与不同div中的SAME类的元素。过滤 - 有点。 – Iladarsda