Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change DIV background color with .click(function(){

How can I change background color with jQuery .click(function(){

div normal with Green color, when clicked change to red background color

<div class="stileone">
   Div Content
</div>
like image 615
Genial Avatar asked Dec 14 '12 16:12

Genial


People also ask

How can change background color of button click in HTML?

Use HTML DOM Style backgroundColor Property to change the background color after clicking the button. This property is used to set the background-color of an element. Example: This example changes the background color with the help of JavaScript.


1 Answers

$(".stileone").on("click", function() {
    $(this).css("background", "red");
})

DEMO

like image 161
Zoltan Toth Avatar answered Sep 29 '22 12:09

Zoltan Toth