I want to remove the “selected” attribute from an option element when I uncheck this. I dont want to make value false or anything… I just want to delete this property. My code is like
$(function() {
$("#deployselect").multiselect({
click: function( event, ui ) {
if(ui.checked==false){
$("#deployselect option[value='"+ui.value+"']").removeAttr("selected");
}
}
});
});
My generated HTML is like this
<option value="68" selected>A1</option>
<option value="49" selected>A2</option>
<option value="69" selected>A3</option>
so even i make “attr” or “prop” false it is not working. 🙁
If you want to de-select it, change this line:
to
Live Example | Source
(Assuming jQuery 1.6 or later; for earlier versions, change
proptoattr.)Once the HTML has been parsed into the DOM, the
optionelement has a property calledselectedwhich gets its initial value from theselectedattribute in the HTML (defaulting tofalse). So once you’re dealing with DOM elements, you’re dealing with a boolean property, not an attribute anymore.