开发者

How to get real object from Jquery?

How to get real object from Jquery selector result? Example:

开发者_JAVA技巧
 $("form").first().id != $("form").first().attr("id")

so this mean result somehow wrapped/delegated with jquery how to unwrap it?


$("div")[0] or $("div").get(0), substituting 0 for the index of the element you want.

If you have multiple DOM elements that you want out, you can use .toArray().


The left operand is incorrect because here:

$("form").first().id

first() returns a jQuery object, so you can't use id (a DOM element property) on it. To get the DOM element wrapped by the jQuery object you use array deferencing:

$("form")[0].id

Or get():

$("form").get(0).id

The following should evaluate to true:

$("form")[0].id == $("form").first().attr("id") 

And therefore this should be false:

$("form")[0].id != $("form").first().attr("id") 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜