You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When changing the selected property using .prop() you're changing the inherent state of the element. The attribute selected only defines the initial state of the document when parsed.
However, when changing the property selected it now also alters the attribute.
Simple code example:
const{load}=require("cheerio");const$=load(`<select><option>1</option><option selected>2</option></select>`);constoption=$("option").eq(0);console.log(option.prop("selected"));// should be falseconsole.log(option.attr("selected"));// should be undefinedoption.prop("selected",true);console.log(option.prop("selected"));// should be trueconsole.log(option.attr("selected"));// should still be undefined, but is "selected"
Notable is that this same behaviour also applies to the checked property.
Interesting issue. cheerio's prop also accesses attributes by default, which is non-standard. I quite like the way prop works in Cheerio at the moment, and will have to think about the best way forward.
When changing the
selected
property using.prop()
you're changing the inherent state of the element. The attributeselected
only defines the initial state of the document when parsed.However, when changing the property
selected
it now also alters the attribute.Simple code example:
Notable is that this same behaviour also applies to the
checked
property.jQuery's docs on
.prop()
The text was updated successfully, but these errors were encountered: