Im using jQuery to disable an option in a select drop down list. I need to know the difference between using
prop('disabled','disabled')
and
prop('disabled',true)
Both pretty much work on all browsers (not sure if I've missed any tho), but on another post I was he say use disable, true. Can someone please elabarate? Thanks
The disabled property sets or returns whether a drop-down list should be disabled, or not. A disabled element is unusable and un-clickable. Disabled elements are usually rendered in gray by default in browsers. This property reflects the HTML disabled attribute.
The disable/enable an input element in jQuery can be done by using prop() method. The prop() method is used to set or return properties and values for the selected elements. Example 1: This example uses prop() method to disable the input text field.
Add one variable like isDisabled = false; Check that variable at the begining of the MyFunction(). And set that variable to true when #x clicked.
Using jQuery The idea is to disable click events inside div with jQuery and CSS. This can be done by setting pointer-events CSS property with the help of jQuery's . addClass() function.
According to the W3C forms specification, the disabled attribute is a boolean attribute,
so prop('disabled',true)
is right.
prop('disabled','disabled')
also works because the string 'disabled'
evaluates to true.
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