I have a jQuery element but I have to send it to a function that only accepts HTML elements. How can I convert the jQuery element to an HTML element?
我有一个jQuery元素,但我必须将它发送到只接受HTML元素的函数。如何将jQuery元素转换为HTML元素?
2 个解决方案
#1
74
Try myJQueryElement.get(0)
or myJQueryElement[0]
. (get()
is most useful when you need negative indices, for example, as described in the documentation for get()
.)
尝试myJQueryElement.get(0)或myJQueryElement [0]。 (get()在需要负索引时最有用,例如,如get()文档中所述。)
#2
21
$("#foo")[0]
will get you an HTML element. Using brackets is a tiny bit faster than using .get()
but not something you'll likely notice unless you are doing it millions of times.
$(“#foo”)[0]将为您提供HTML元素。使用括号比使用.get()快一点,但不是你可能会注意到的东西,除非你做了数百万次。
#1
74
Try myJQueryElement.get(0)
or myJQueryElement[0]
. (get()
is most useful when you need negative indices, for example, as described in the documentation for get()
.)
尝试myJQueryElement.get(0)或myJQueryElement [0]。 (get()在需要负索引时最有用,例如,如get()文档中所述。)
#2
21
$("#foo")[0]
will get you an HTML element. Using brackets is a tiny bit faster than using .get()
but not something you'll likely notice unless you are doing it millions of times.
$(“#foo”)[0]将为您提供HTML元素。使用括号比使用.get()快一点,但不是你可能会注意到的东西,除非你做了数百万次。