Disabled HTML and Jquery property

Asked

Viewed 824 times

2

Someone knows why they are not disabling the (disabled) property in jquery. That is, when you click the button.I want you to be (disabled=false)

    $(document).ready(function(){

        $("#b2").click(function(){

       $("input").prop(disabled,false);

           });
    });
    </script>
</head>
<body>



    <input  disabled="true">

    <button id="b2">botao</button>

</body>

2 answers

2

You have to wear a String for the name of the property.

Mute

.prop(disabled, false);

for

.prop('disabled', false);

$(document).ready(function() {
  $("#b2").click(function() {
    $("input").prop('disabled', false);
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input disabled="true">

<button id="b2">botao</button>

  • 1

    Thanks worked out

2


To change properties or attributes of an element with jQuery, in the syntax, the name of the attribute and the value should come in quotes:

$('elemento').prop('atributo', 'valor');

In the case of disabled, for being a value boolean, can be outside the quotation marks:

$('elemento').prop('disabled', false);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.