如果我有一个变量和一个jQuery,如何执行查询并获取第一个结果DOM元素本身(如果有)?

var $myQuery = $(...)
var domNode = $.myQuery<what to write here?> // and what if the query has not results?

最佳答案

这将返回本机DOM对象

var domNode = $myQuery[0] //undefined if there is not any element.


要么

var domNode = $myQuery.get(0) // Identical to above, only slower (according to doc).


资源资源


How do I pull a native DOM element from a jQuery object?

10-05 20:37
查看更多