Reputation: 1036
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?
Upvotes: 0
Views: 595
Reputation: 79830
Try using .prop
like below,
$('[id$=ddlInsert4]').prop('disabled', true);
You can use jQuery .prop
function like above
or
$('[id$=ddlInsert4]')
returns a jquery object (selector always returns array of jQuery object) so You cannot set DOM properties on jQuery object like that..
You need to iterate in a loop and set the property ex: $('[id$=ddlInsert4]')[i].disabled = true
where i
is the index.
Upvotes: 5
Reputation: 227200
obj
is a jQuery object, not a DOM element. You need to do $(obj).prop('disabled', true);
. Or better yet, if you don't need the obj
variable elsewhere, just do:
$('[id$=ddlInsert4]').prop('disabled', true)
To interact with native DOM elements, you can do [0]
(or .get(0)
). Then you can do:
obj[0].disabled = true;
(note that the property is disabled
not disable
)
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 .prop
method though, as it will loop over all the elements for you.
Upvotes: 2