Changing the background color of a
section

后端 未结 3 792
无人及你
无人及你 2021-01-24 16:41

I\'m trying to use jQuery to change the background color of a

section when pressing on a button, and below is the code to do that. Why isn\
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-24 17:35

    You have several problems:

    1. Your selector is wrong: $("#bgcolor")
    2. You're missing a closing
    tag.
  • You need jQueryUI to animate background-color.
  • HTML:

    
    
    Abder-Rahman

    JS:

    $("#bgcolor").click(function(){
        $("#name").animate(
            {backgroundColor: '#8B008B'},
            "fast");}
    );
    

    Your code, fixed (and working with jQueryUI included): http://jsfiddle.net/andrewwhitaker/rAVj9/

提交回复
热议问题