Selected items in the listbox will show up in the UL below. Click on an item in the UL and it will remove it from the listbox and remove itself from the UL.
Reproduce Bug: http://jsfiddle.net/rkw79/mmBKf/2/
Notice that the event is fired, but the item is not added
Now do the same steps, except use .prop('selected','') instead of .removeProp('selected'): http://jsfiddle.net/rkw79/mmBKf/3/
jQuery removeProp() MethodThe removeProp() method removes a property set by the prop() method. Note: Do not use this method to remove HTML attributes like style, id, or checked. Use the removeAttr() method instead.
jQuery prop() Method The prop() method sets or returns properties and values of the selected elements. When this method is used to return the property value, it returns the value of the FIRST matched element.
prop() method provides a way to explicitly retrieve property values, while . attr() retrieves attributes. For example, selectedIndex, tagName, nodeName, nodeType, ownerDocument, defaultChecked, and defaultSelected should be retrieved and set with the . prop() method.
Everything you need to know is in the documentation.
With some built-in properties of a DOM element or window object, browsers may generate an error if an attempt is made to remove the property. jQuery first assigns the value undefined to the property and ignores any error the browser generates. In general, it is only necessary to remove custom properties that have been set on an object, and not built-in (native) properties.
Note: Do not use this method to remove native properties such as checked, disabled, or selected. This will remove the property completely and, once removed, cannot be added again to element. Use
.prop()
to set these properties tofalse
instead.
You should be using removeAttr()
$('myele").attr('selected'); // <myele /> --> <myele selected />
$('myele").removeAttr('selected'); // <myele selected /> --> <myele />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With