how to remove event listener in jquery


// adding an event listener using jQuery
$('h1').click(()=>{
console.log('clicked')
})

// unbinding event listener
$('h1').unbind()

//Remove all event handlers from all paragraphs:

$( "p" ).off();

//Remove all delegated click handlers from all paragraphs:

$( "p" ).off( "click", "**" );

www.codegrepper.com
www.stackoverflow.com

how to receive window.postmessage event in angular 9


receiveMessage: any = (event: any) => {
//...
}

window.addEventListener("message", () => {
this.receiveMessage();
}, false)

constructor(private _authService: AuthService, private _router: Router) {
if (window.addEventListener) {
window.addEventListener("message", this.receiveMessage.bind(this), false);
} else {
(<any>window).attachEvent("onmessage", this.receiveMessage.bind(this));
}
}

www.codegrepper.com
www.stackoverflow.com

how to prevent event capturing in javascript


how to prevent event button click capturing to tag/div/icon
easiest way OPTION 1 with CSS:
button > * {
pointer-events: none;
}

OPTION 2 with javascript:
use e.currentTarget.children ;

OPTION 3 with Javascript:
use e.target.closest('selector') to locate the child, not e.currentTarget;

www.codegrepper.com
www.stackoverflow.com