我有一些DOM对象和对象选择器。 JQuery中是否有办法选择两者的混合集?以下是我尝试过的内容:
// Note that in the real code, I don't know how el1 and el2 were obtained.
// They may have associated id fields, or they may not.
let el1 = document.getElementById('id1');
let el2 = $('#container > div > span').get();
let groupSelector = $([el1, el2, '#id3, div > span']);
我知道,如果所有元素都有ID,或者我知道原始的选择器,我可以将它们简单地连接成一个逗号分隔的列表。但是,并非所有这些元素都具有ID,并且我不知道原始的选择器。如何创建包含示例代码中指示的项目的单个JQuery容器?
[来自@Taplar的评论:
let groupSelector = $('#id3, div > span').add([el1, el2]);