jQuery 获取 DOM 节点?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2316199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 13:14:14  来源:igfitidea点击:

jQuery get DOM node?

jquerydom

提问by mpen

Possible Duplicate:
How to get a DOM Element from a JQuery Selector

可能的重复:
如何从 JQuery 选择器获取 DOM 元素

I can select a node using jQuery with something like $('#element_id')but how would I get the DOM element for use with non-jQuery functions that expect something like would be returned by document.getElementById()?

我可以使用 jQuery 选择一个节点,$('#element_id')但我将如何获取 DOM 元素以与非 jQuery 函数一起使用,这些函数期望类似的东西会被返回document.getElementById()

回答by cletus

You can retrieve DOM elements using array notation:

您可以使用数组表示法检索 DOM 元素:

$("#element_id")[0]

or with get():

或与get()

$("#element_id").get(0)