1

I am getting an error object property doesn't support this method when I try to remove the attribute when I load the page.

However I believe this is happening because the disabled attribute was never added on page load, because I do not receive the error after the attribute is added.

My question is how can I check if the attribute exists before trying to remove it.

Thanks

 if (jQuery.inArray($("select option:selected").val(), Codes) == -1) {
                $(serviceSelector).hide();
                $(LocationSelector).hide();

                $("#ctl00_ctl00_body_body_ddlPool option['value=ADD']").removeAttr("disabled");
                $("#ctl00_ctl00_body_body_ddlPool option['value=ADM']").removeAttr("disabled");
            } else {
                $(serviceSelector).show();
                $(LocationSelector).show();
                $("#ctl00_ctl00_body_body_ddlPool  option[value=ADM]").attr("disabled", "disabled");
                $("#ctl00_ctl00_body_body_ddlPool  option[value=ADD]").attr("disabled", "disabled");

            }
            //$find(AcId).set_contextKey($(this).val());
        }).change();
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
HELP_ME
  • 2,619
  • 3
  • 24
  • 31
  • 1
    Please see this question: http://stackoverflow.com/questions/1318076/jquery-hasattr-checking-to-see-if-there-is-an-attribute-on-an-element – brandwaffle Dec 23 '11 at 16:37
  • 5
    You have syntax errors in your selectors: `option['value=ADD']` should be `option[value='ADD']` (and similarly for other `[name='value']` selectors). – Andrew Whitaker Dec 23 '11 at 16:38

1 Answers1

6

You can use the .hasAttribute method

If you have more than one of each ADD and ADM nodes you will have to test each one:

$("#ctl00_ctl00_body_body_ddlPool option[value='ADD']").each(function(){
    if(this.hasAttribute("disabled"))
        this.removeAttribute("disabled");
});

Otherwise just test against the actual node

if($("#ctl00_ctl00_body_body_ddlPool option[value='ADD']")[0].hasAttribute("disabled"))

EDIT: fixed syntax error per Andrew's comment.

Joseph Marikle
  • 76,418
  • 17
  • 112
  • 129
  • He's right - Also, it's really helpful to use a debugging console like [firebug](http://www.getfirebug.com) or [developer tools](http://code.google.com/chrome/devtools/docs/overview.html#access). The console is your friend. – Chazbot Dec 23 '11 at 16:43