Coding Filters & disable a button using jquery project details

Disable a button with JQuery!

To disable a button using jQuery, you can use the .prop() method to set the disabled property of the button to true.

Example:

#html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Disable Button with jQuery</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>

    <button id="myButton">Click Me</button>
    <button id="disableButton">Disable</button>

    <script>
        $(document).ready(function(){
            // Disable button when another button is clicked
            $('#disableButton').click(function(){
                $('#myButton').prop('disabled', true);  // Disable the button
            });
        });
    </script>

</body>
</html>

Review:

  • HTML Structure:
    • Two buttons are defined: one to be disabled (#myButton) and the other to trigger the disabling action (#disableButton).
  • jQuery Code:
    • When the #disableButton is clicked, the jQuery .prop() method is used to set the disabled attribute of the #myButton to true.

This will disable the button and prevent users from interacting with it. If you want to re-enable the button later, you can set the disabled property to false:

#jquery
$('#myButton').prop('disabled', false);  // Enable the button

Developers Simplify Complex Code at Coding Filters!

Developers often struggle with overly complex code that is hard to maintain and debug. By applying coding filters, developers can break down complex tasks into smaller, more manageable pieces, resulting in simpler, cleaner code. Filters help to target specific data or processes, enhancing both performance and readability.

Author

  • theaamirlatif

    Frontend Web Dev and UI/UX Engineer, cross-browser, responsive design, user interaction, web accessibility, and client-side optimization in React, WP, Apps Dev.

    View all posts

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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