-2

I am new to stackoverflow.

I am using jQuery for an application. Because of some reasons the onclick submit is not working to change the color of the submit button.

Here's a minimal demonstration of my problem.

$(document).ready(function() {
   $("input[type='submit']").onClick(function(){
      $(this).css('background-color','red');
    });
});
.blue{
  background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<input type="submit" value="submit" class="blue">
</form>

1 Answers1

0

Try using...

   
 $(document).ready(function() {
    $('#my-form').on('submit', function(){
      $(this).css('background-color','red');
    });
  });

Using this code above is specifically for form submission rather then using the .click. If you do use this, you will also have to specify . or # for in front of your my-form element as it is declared in your html like so..#my-form or .my-form depending on if it is a class (.) or a id (#)

  • 4
    This is incomplete.. You will need to specify an ID to the form ie: `id="my-form"`.. And use `$('#my-form')` Please give full answers. – Pogrindis Aug 31 '17 at 15:13