Add/remove class on click to change background color of a div
问题 I've been trying to get a little black div to change color to green on click and change it back to black on the next click. I want it to keep doing this. Unfortunately it doesn't seem to work and through checking other topics on this I couldn't find my answer. My HTML: <div id="block"></div> My CSS: div { width: 100px; height: 100px; background-color: black; } My jQuery: $(function(){ $("#block").click(function(){ if($(this).hasClass("faded") == false) { $(this).css("background-color", "green