javascript - jQuery addClass click and removeClass when click again -
i have box without color. if box being click() addclass('.red') make red, , if click again box color change blue. change alternatively. , don't know how make it.
code
html
<div class='box'></div> css
.box { width: 250px; height: 100px; border: 1px #000 solid; } .red { background: red; } .blue { background: blue; } javascript
$('div').click(function() { $(this).addclass('red'); });
try toggleclass like
$('div').click(function() { $(this).toggleclass("red"); }); if want toggle 2 classes red , blue use like
$('div').click(function() { $(this).toggleclass("red blue"); });
Comments
Post a Comment