In my reactjs app there are the component 'Modal'. It's an absolutely positionned block with x-index: 1000. One button in the component 'Menu' opens this modal in the main page. There is a function closing the modal box by clicking only outside the box. But modal closes by both outside and inside clicks - any conditions about clicking on the modal doesn't work and the box closes. Why doesn't work conditions like 'id' or 'z-index' of the modal box?
const clickOutModal= (event) => {
if(event.target.id !== 'mymodal') { //condition when modal box mustn't close
clickModalClose(); // working function based on useState for closing the modal box
}
};
document.body.addEventListener('click', clickOutModal);
The second variant of condition I tried was
if(event.target.zIndex !== '1000')