jquery change button color onclick

后端 未结 5 508
自闭症患者
自闭症患者 2021-02-04 11:04

I have multiple buttons that I use when people answer a question. How would I get the buttons to change colors when a person clicks on the button? I do not know jquery, I have b

5条回答
  •  我在风中等你
    2021-02-04 11:25

    You have to include the jquery framework in your document head from a cdn for example:

    
    

    Then you have to include a own script for example:

    (function( $ ) {
    
      $(document).ready(function(){
          $('input').click(function() {
              $(this).css('background-color', 'green');
          }
      });
    
    
      $(window).load(function() { 
      });
    
    })( jQuery );
    

    This part is a mapping of the $ to jQuery, so actually it is jQuery('selector').function();

    (function( $ ) {
    
    })( jQuery );
    

    Here you can find die api of jquery where all functions are listed with examples and explanation: http://api.jquery.com/

提交回复
热议问题