javascript - jquery 中 .add() 的等效 javascript 函数是什么?

标签 javascript jquery

例如,对于给定的 jquery 片段,等效的 javascript 应该是什么。 JavaScript 中的等效 add 方法可能会有所帮助。

$("h1").add("span").add("h2");

正如 jquery 文档中明确提到的那样 - .add() 不会添加任何 DOM 元素。 https://api.jquery.com/add/因此,使用 .appendChild() 在这里不起作用

最佳答案

文档位于https://api.jquery.com/add

"Given a jQuery object that represents a set of DOM elements, the .add() method constructs a new jQuery object from the union of those elements and the ones passed into the method. ".

该方法不执行任何 DOM 操作,它纯粹用于操作 jQuery 对象。据我所知,没有直接的等价物 - 如果您不使用 jQuery,那么根据定义,您无法创建或操作 jQuery 对象。

附注您始终可以检查该方法的 jQuery 源代码以了解它的作用。

关于javascript - jquery 中 .add() 的等效 javascript 函数是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52295545/

相关文章:

javascript - 如何在 jquery.datatables 中显示复选框?

javascript - 数字的比例和精度

jquery - 参数列表后缺少 ) ? jQuery

javascript - 从 JS 客户端在 SignalR 控制台应用程序上进行身份验证

JavaScript 本地存储

javascript - 安卓 WebView : is there a way to get a javascript stack trace?

javascript - Puppeteer 中主函数和渲染器函数之间的通信

jQuery Mobile 列表过滤器的行为类似于自动完成

javascript - 如何将事件类添加到基于每个页面中的 URL 的导航菜单

javascript 显示/隐藏目录