Here is my code –
var obj = $('[id$=ddlInsert4]')
obj.disable = true;
obj is a drop down list, but the disable call doesn’t disable the drop down list.
alert(obj.val()) //this returns the correct value
Since my alert is returning the correct value, I know my jQuery syntax is correct.
What am I missing?
objis a jQuery object, not a DOM element. You need to do$(obj).prop('disabled', true);. Or better yet, if you don’t need theobjvariable elsewhere, just do:To interact with native DOM elements, you can do
[0](or.get(0)). Then you can do:(note that the property is
disablednotdisable)Note:
$('[id$=ddlInsert4]')can return multiple elements, and[0]will just get the first one. You’d need to loop over all of them, if there were more than one. I suggest using the jQuery.propmethod though, as it will loop over all the elements for you.