0
votes

This is a part of my script using jQuery.

        jQuery(".disabableInputField").addClass("disabledInputField");
        cstaIpVal[0] = jQuery("#private-circuit-to-csta-subnet").val();
        cstaIpVal[1] = jQuery("#private-circuit-to-csta-subnet\\.netmask").val();
        jQuery("#private-circuit-to-csta-subnet\\.netmask").val("");
        jQuery("#private-circuit-to-csta-subnet").val("");
        jQuery(".disabableInputField").attr("disabled",true);           
        jQuery("#private-circuit-to-csta-subnet\\.netmask").prop("path", "");
        jQuery("#private-circuit-to-csta-subnet").prop("path","");

The question is, why the combination of calling prop and attr doesn't work. If I call attr("disabled",true) then the property set prop("path","") does not work. When I switch the order, then attribute set does not work. I can not achieve setting disabled attribute via prop. How can I combine attr and prop calling? Or how can I set disabled attribute of html element via prop calling?

Thank you.

2
You're misusing both methods. prop is for disabled, attr is for custom attributes (path)hindmost

2 Answers

2
votes

You can disable element with :

jQuery(".disabableInputField").prop("disabled", true);

See : https://learn.jquery.com/using-jquery-core/faq/how-do-i-disable-enable-a-form-element/

And maybe this : .prop() vs .attr()

1
votes

I guess it's becouse of missuse of methods. Use "prop" for setting properties, and "attr" for setting attributes. Not vice verse. The following worked fine for me.

<input type="text" id="test" />
<script type="text/javascript">
    jQuery("#test").prop("disabled",true);
    jQuery("#test").attr("path", "");
</script>
<!-- result -->
<input disabled="" id="test" type="text" path="">