Help please, I want to understand how to implement click outside diva. It is necessary to transfer the focus from video to page when you click outside the video, also back. There is a good example from the English version of the site: https://stackoverflow.com/questions/18893144/javascript-detect-click-event-outside-of-div , but its problem is that the video diva is in the main container and the function is always called, just when you click on the video. Tell me how to implement this?
- Well, and filter the events on hit in the video - tutankhamun
|
1 answer
var specifiedElement = document.getElementById('a'); //I'm using "click" but it works with any event document.addEventListener('click', function(event) { var isClickInside = specifiedElement.contains(event.target); if (!isClickInside) { //the click was outside the specifiedElement, do something } }); getElementById - here you specify the item ID in your case this video
if (!isClickInside) { // Здесь то, что нужно делать, когда кликнул вне элемента } - Thanks, simple and clear. - Vladyslav Semenyuk February
|