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>
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>
DEMO
I know there are plenty answers here, but i thought I would point out, there are many ways to accomplish this and many with slightly different purpose.
See examples here!
Work with
.on()
. You bind an event on your<div.stileone>
when the event'click'
occurs, then you reference to your<div.stileone>
object within the function with$(this)
. And toggleClass adds/removes the class every time the Event is triggered.jQuery:
css:
you need to find the onclick event to the div, then use