JackShcherbakov
@JackShcherbakov

Как сделать так, что бы при повторном клике цвет исчезал?

Вот код на jsfiddle, там почему-то jquery не хочет подключаться.https://jsfiddle.net/CitizenOne/m4cd5n79/1/
Ну а вот сам код. Надо что бы при повторном клике на клетку цвет исчезал.
<!DOCTYPE html>
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Game For Yan</title>
<script src="jquery-3.2.1.min.js"></script>
<script src="jquery-ui.min.js"></script>
<script>
	$(document).ready(function(){
		$('#game').hide();
		$('#start').click(function(){
			$(this).hide();
			$('.menu').hide();
			$('#game').slideDown(300);
			$('.play').hide();
		});
		var color;
		$('#colors div').click(function(){
			color = $(this).attr('class');
			$('#colors div').removeClass('checked');
			$(this).addClass('checked');	
		});
		$('table').on('click', 'td', function(){
				$(this).removeClass(color);//Внимание сюда
				$(this).toggleClass(color);
		});
		$('.lol').mouseover(function(){
			$('td').removeClass();
		});
		$('.clean').click(function(){
			$('td').removeClass();
		});
	});
</script>
<style>
body{
	margin:0;
	font-family:Arial, Helvetica, sans-serif;
	background:url('img/bg.jpg');
}
#start{
	width:500px;
	height:50px;
	cursor:pointer;
	color:white;
	border-radius:50px;
	transition:0.3s;
	border:6px white solid; 
	background-color:#0099FF;
	position:absolute;
	left:750px;
	top:80px;
	text-align:center;
	font-size:30px;
}
#start:hover{
	background-color:#3366CC;
}
#start p{
	margin:0;
	padding-top:7px;
}
.play{
	width:100%;
	height:250px;
	background-color:#333333;
	margin-top:50px;
	position:relative;
}
table{
	margin:0 auto;
	border-collapse: collapse;
}
td{
	border:3px #333333 solid;
	cursor:pointer;
	margin:5px;
	background-color:white;
	height:80px;
	width:80px;
}
#colors{
	margin:0 auto;
	margin-top:30px;
	width:100%;
	background-color:#333333;
	padding:15px 0 15px 15px;
	text-align:center;
	position: relative;
}
#colors > div{
	width:50px;
	height:50px;
	display:inline-block;
	margin-right:15px;
	cursor:pointer;
}
#colors p{
	color:white;
	margin:0;
	margin-top:15px;
	font-size:20px;
}
/********************СOLORS********************/
	.blue{
		background-color:#FFCCFF;
	}
	.red{
		background-color:red;
	}
	.yellow{
		background-color:#FFFF33;
	}
	.white{
		background-color:#FFFFFF;
	}
	.green{
		background-color:#999933;
	}
	.gray{
		background-color:#999999;
	}
	.red{
		background-color:#FF0000;
	}
	.black{
		background-color:#000000;
	}

	.yan{
		background-image:url('colors/yan.jpg');
	}
	.yel{
	background-image:url('colors/yel.jpg');
	}
	.car{
	background-image:url('colors/car.jpg');
}
/********************СOLORS********************/
.clean{
	width:150px;
	height:50px;
	background-color:#0099FF;
	cursor:pointer;
	color:white;
	text-align:center;
	border-radius:50px;
	transition:0.3s background-color;
	display: inline-block;
	position: absolute;;
}
.clean:hover{
	background-color:#3366CC;
}
.clean p{
	margin:0;
}
.checked{
	border-bottom: 6px white solid;
}
h1{
	text-align:center;
	background-color:#333333;
	color:white;
	padding:15px 0 15px 0;
}
.video{
	width:1690px;
	margin:0 auto;
}
</style>
</head>

<body>
<div class="play">
	<div id="start"><p>Рисовать!</p></div>
</div>
<div class="menu">
	<h1>МУЛЬТИКИ</h1>
	<div class="video">
		<iframe width="560" height="315" src="https://www.youtube.com/embed/T4twqnmPjpQ" frameborder="0" allowfullscreen></iframe>
		<iframe width="560" height="315" src="https://www.youtube.com/embed/2ZdNT4VwKuM" frameborder="0" allowfullscreen></iframe>
		<iframe width="560" height="315" src="https://www.youtube.com/embed/sajgcqs1xio" frameborder="0" allowfullscreen></iframe>
		<iframe width="560" height="315" src="https://www.youtube.com/embed/TiX-6A2Cn30" frameborder="0" allowfullscreen></iframe>
		<iframe width="560" height="315" src="https://www.youtube.com/embed/7OHMqdMpsj8" frameborder="0" allowfullscreen></iframe>
		<iframe width="560" height="315" src="https://www.youtube.com/embed/4IfmzhwzPVM" frameborder="0" allowfullscreen></iframe>
		<iframe width="560" height="315" src="https://www.youtube.com/embed/4SJ6SNiXcOw" frameborder="0" allowfullscreen></iframe>
		<iframe width="560" height="315" src="https://www.youtube.com/embed/bR-fdVxHO8M" frameborder="0" allowfullscreen></iframe>
		<iframe width="560" height="315" src="https://www.youtube.com/embed/z-bTLD7fESY" frameborder="0" allowfullscreen></iframe>
		<iframe width="560" height="315" src="https://www.youtube.com/embed/n_YRqcIN2-0" frameborder="0" allowfullscreen></iframe>	
		<iframe width="560" height="315" src="https://www.youtube.com/embed/-L7xUFmNzYs" frameborder="0" allowfullscreen></iframe>
		<iframe width="560" height="315" src="https://www.youtube.com/embed/YnltFSl_DQ0" frameborder="0" allowfullscreen></iframe>
	</div>
</div>
<div id="game">
	<h1>Игра для Яна</h1>
	<table cellspacing="0">
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>

		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>

		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
		</tr>
			<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
		</tr>
			<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
		</tr>
	</table>
	<div id="colors">
		<div class="white"></div>
		<div class="red"></div>
		<div class="blue"></div>
		<div class="yellow"></div>
		<div class="green"></div>
		<div class="blue"></div>
		<div class="gray"></div>
		<div class="black"></div>
		<div class="yan"></div>
		<div class="yel"></div>
		<div class="car"></div>
		<article class="clean"><p>Отчистить</p></article>
		<p>Выбери цвет!</p>
	</div>
</div>
</body>

</html>
  • Вопрос задан
  • 208 просмотров
Решения вопроса 1
cashalot
@cashalot
Если я вам помог - пометьте мой ответ как решение
Вот тут
$('table').on('click', 'td', function(){
        $(this).removeClass(color);
        $(this).toggleClass(color);
    });

Удалите строку - $(this).removeClass(color);
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы