Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery background color change on button click

Why doesnt this work?

jquery

$("#button").click(function(){ 
 $("go").css("background-color","yellow");
 });

html

<table><tr id=go bgcolor=#010609><td>hello</td></tr</table>
<input type=button id=button>
like image 714
user1022585 Avatar asked Mar 22 '12 11:03

user1022585


People also ask

How can change background color of button click in jQuery?

JavaScript Code:$("div"). on( "click", "button", function( event ) { $(event. delegateTarget ). css( "background-color", "green"); });

How can set background color in jQuery?

To add the background color, we use css() method. The css() method in JQuery is used to change style property of the selected element. The css() in JQuery can be used in different ways. The css() method can be used to check the present value of the property for the selected element.

How do I change the background color of all html buttons with class test using jQuery?

attr("data-color"); $("."+class). css("background-color",color); }); . button is the class to apply to the button, add data-class for the class you would like to change the background color of, and data-color is the color you would like to change it to.


1 Answers

go is an id :

$("#button").click(function(){ 
    $("#go").css("background-color","yellow");
});
like image 176
mgraph Avatar answered Oct 23 '22 10:10

mgraph