JavaScript change disabled attribute | Dynamically disabled it using JS code

  • by

Just set the disabled property to false in JavaScript, it will change the disabled attribute in HTML. If you set disabled property true then HTML elements will disable.

document.getElementById("myId").disabled = false;

JavaScript change disabled attribute value example

HTML example code will disable an input button.

<html>
<body>

    <input id="dummy" type="button"  value="Submit" />
    
</body>
<script>

    var elem = document.getElementById('dummy');

    elem.disabled = true;
    
</script>
</html>

Output:

JavaScript change disabled attribute

Do comment if you have any doubts and suggestions on this topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.