2

https://jsfiddle.net/LightFlight/vw7LbqLa/2/

$('.wrapper').on('click', function() {
  $('.inner').toggleClass('color');
});
.wrapper {
  width: 300px;
  height: 300px;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  margin: auto;
  background-color: #aaa;
  padding: 10px;
}
.inner {
  height: 50px;
  background-color: #0B5CE8;
  margin: 20px;
}
.color {
  background-color: #8FAFFF;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<div class="wrapper">
  <div class="inner" id="noAction"></div>
  <div class="inner"></div>
  <div class="inner"></div>
</div>

Как сделать так, чтобы при клике на первый голубой блок событие 'click' не срабатывало?

1 ответ 1

2
$('.wrapper').on('click', function(e) {
    if(e.target.id === 'noAction') return false;
    $('.inner').toggleClass('color');
});

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.