Показать сообщение отдельно
  #11 (permalink)  
Старый 24.07.2017, 02:21
Аватар для j0hnik
Профессор
Отправить личное сообщение для j0hnik Посмотреть профиль Найти все сообщения от j0hnik
 
Регистрация: 01.12.2016
Сообщений: 3,650

Рони, чутка улучшил.
<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<style>
		form{
			width: 200px;
			height: 100px;
			border: 1px solid red;
		}
		div{
			display: inline-block;
			width: 50px;
			height: 50px;
			border: 1px solid green;
		}
		.active{
			background-color: #8B4513;
		}

	</style>
</head>
<body>
	<form action="">
		<div>1</div>
		<div>2</div>
		<div>3</div>
		<button disabled>кнопка</button>
	</form>
	<script>
		document.querySelector('form').addEventListener("click", function(e){
			var target = e.target;
			if (target.tagName === 'DIV') target.classList.toggle('active');
			else document.querySelectorAll('div').forEach( el => el.classList.remove("active"));
			document.querySelector('button').disabled = !document.querySelector('div.active');
		});
	</script>
</body>
</html>
Ответить с цитированием