Mark Schultheiss
Mark Schultheiss

Reputation: 34196

get root element on selector

Is there a way to get the root element on a selector?

It came to my attention that a selector such as

document.getElementById("chk").checked

gets the property for a checkbox - and if it changes, it reflects that value.

For jQuery 1.9.1

$("#chk").checked

no longer returns the property whereas

$("#chk").prop('checked');

does return the property.

My question is, is there a way, from a selector jQuery object such as $('#chck') to get the base element so that a .checked would work?

Note that I filed a jQuery bug on the checkbox property issue, as that seems like it should work but that is not my question specifically.

Upvotes: 0

Views: 108

Answers (1)

adeneo
adeneo

Reputation: 318302

$("#chk")[0].checked
$("#chk").get(0).checked

etc ...

This is the intended funcionality, .checked only works on native DOM elements, while prop() is a jQuery method.

Upvotes: 2

Related Questions