Jquery 通过变量选择器
Jquery selector through variables
我怎样才能实现以下目标:
$('#someId, #anotherId').addClass('newKlass');
使用变量,而不必为每个 .addClass
操作写一个新行。我不想必须执行以下操作:
firstEl = $('#someId');
secondEl = $('#anotherId');
firstEl.addClass('newKlass');
secondEl.addClass('newKlass');
做一个数组!
var elms = ["#this","#that"];
elms.forEach(function(elm){
$(elm).addClass('blue');
})
我怎样才能实现以下目标:
$('#someId, #anotherId').addClass('newKlass');
使用变量,而不必为每个 .addClass
操作写一个新行。我不想必须执行以下操作:
firstEl = $('#someId');
secondEl = $('#anotherId');
firstEl.addClass('newKlass');
secondEl.addClass('newKlass');
做一个数组!
var elms = ["#this","#that"];
elms.forEach(function(elm){
$(elm).addClass('blue');
})