0

How do I access .show-video-player if someone clicks on .video-play-pause? This is what I have so far, but it doesn't work.

$('.video-play-pause').on('click', (e) => {
  $(this).parent().next('.show-video-player').toggle();
  alert($(this).parent().next('.show-video-player').length);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="lesson">
  <div class="video-play-pause" data-url="{{url}}">video-play-pause</div>
</div>
<div class="show-video-player">show-video-player</div>
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Chris Hansen
  • 7,813
  • 15
  • 81
  • 165
  • 1
    Hi try accessing it like this `$(event.currentTarget).parent().next('.show-video-player').toggle();` .Also have a look at [this](https://stackoverflow.com/a/27670450/10606400) answer to know reason. – Swati Nov 18 '20 at 13:53

1 Answers1

1

When accessing the parent of the clicked element, use event instead of this keyword. So you can change your selector to below: $(e.target).parent().next('.show-video-player').toggle()

Placide
  • 67
  • 1
  • 6