I\'d like to detect a click inside or outside a div area. The tricky part is that the div will contain other elements and if one of the elements inside the div is clicked, i
In Angular 6 and IONIC 3, I do same as here:
import {Component} from 'angular/core';
@Component({
selector: 'my-app',
template: `
`
})
export class AppComponent {
onClick(event) {
var target = event.target || event.srcElement || event.currentTarget;
if (document.getElementById('warning-container').contains(target)){
// Clicked in box
} else{
// Clicked outside the box
}
}
}
This working fine on web/android/ios. It might be helpful for someone, Thanks.