开发者

Combing selectors that are saved as vars

开发者 https://www.devze.com 2023-02-16 10:50 出处:网络
I know it\'s possible to combine the first 2 lines to something like line 3 where the 2 selectors are separated by ,

I know it's possible to combine the first 2 lines to something like line 3 where the 2 selectors are separated by ,

$('#divid input[name=some]').val('');
$('#divid input[name=thing]').val('');

$('#divid input[name=some], #divid input[name=thing]').val('');

But if I have them saved as objects obj1 and obj2, how do I select them together the same way?

var obj1 = $('#divid input[name=some]');
var obj2 = $('#divid input[name=thing]开发者_StackOverflow');

I tried all this but they didn't work. Can it be done?

obj1,obj2.val('');
(obj1,obj2).val('');
$(obj1,obj2).val('');


You can use the add() method:

var obj1 = $('#divid input[name=some]');
var obj2 = $('#divid input[name=thing]');
obj1.add(obj2).val('');


Try

var object = $.extend({}, object1, object2);

Reference

0

精彩评论

暂无评论...
验证码 换一张
取 消