JS:
/*button_menu_moblie*/
function OP_menu_MB() {
document.getElementsByClassName("menu_reponsive")[0].classList.toggle("active_menu");
}
JS:
/*button_menu_moblie*/
function OP_menu_MB() {
document.getElementsByClassName("menu_reponsive")[0].classList.toggle("active_menu");
}
Ví dụ:
const menu = document.querySelector('.menu_reponsive');
window.addEventListener('click', function(e) {
if( !menu.contains(e.target) ) {
// Click ngoài menu, viết code đóng menu ở đây
}
})
cho mình hỏi target ở đây nghĩa là j vậy
e
ở đây là MouseEvent được kế thừa từ Event. target
là 1 property của Event, ở trường hợp này là element xảy ra sự kiện click (tức là mình click vào element nào).
Trong đoạn code trên mình kiểm tra nếu element mình click nó không nằm trong menu thì tức là mình click bên ngoài menu.
Cảm ơn bạn mình đã hiểu r