jquery change button color onclick

后端 未结 5 506
自闭症患者
自闭症患者 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-04 11:05

    $('input[type="submit"]').click(function(){
    $(this).css('color','red');
    });
    

    Use class, Demo:- http://jsfiddle.net/BX6Df/

       $('input[type="submit"]').click(function(){
              $(this).addClass('red');
    });
    

    if you want to toggle the color each click, you can try this:- http://jsfiddle.net/SMNks/

    $('input[type="submit"]').click(function(){
      $(this).toggleClass('red');
    });
    
    
    .red
    {
        background-color:red;
    }
    

    Updated answer for your comment.

    http://jsfiddle.net/H2Xhw/

    $('input[type="submit"]').click(function(){
        $('input[type="submit"].red').removeClass('red')
            $(this).addClass('red');
    });
    

提交回复
热议问题