1

I have a button in my application :

<button name="download" id="download" type="submit" class="btn primary" style="margin:0;">Next</button>

How can I disable this button and re-enable it using JQuery ?

I tried below code but it doesn't works.

$('#download').attr('disabled', 'disabled');
 $('#download').removeAttr('disabled');

TIA :)

2
  • when u need to disable ? Commented Feb 26, 2015 at 5:01
  • your code is working ... make sure you have only one element inside DOM with id download Commented Feb 26, 2015 at 5:03

2 Answers 2

1

Try something like this,

<!DOCTYPE html>
<html>
<head>
    <script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.js'></script>
    <script type='text/javascript'>
    //<![CDATA[ 
      $(window).load(function(){
        $('button#download').prop('disabled', true);
        alert('hello');
        $('button#download').removeAttr('disabled');
      });
    //]]>  
    </script>
</head>
<body>
  <button name="download" id="download" type="submit" class="btn primary" style="margin:0;">Next</button>
</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

0

Below code if you have text box that is empty the submit button ill be disbaled if the textbox is not empty submit button not disabled

   $(document).ready(function() {
         $('input[type="submit"]').attr('disabled','disabled');
         $('input[type="text"]').keyup(function() {
            if($(this).val() != '') {
               $('input[type="submit"]').removeAttr('disabled');
            }
         });
     });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.