Interruzione di un evento (click, ...)
Versione del 22 lug 2024 alle 15:10 di Andrea (discussione | contributi) (Creata pagina con "← jQuery e Javascript Category:jQuery == event.stopImmediatePropagation() == fonte: https://api.jquery.com/event.stopImmediatePropag...")
event.stopImmediatePropagation()
fonte: https://api.jquery.com/event.stopImmediatePropagation/
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>event.stopImmediatePropagation demo</title>
<style>
p {
height: 30px;
width: 150px;
background-color: #ccf;
}
div {
height: 30px;
width: 150px;
background-color: #cfc;
}
</style>
<script src="https://code.jquery.com/jquery-3.7.0.js"></script>
</head>
<body>
<p>paragraph</p>
<div>division</div>
<script>
$( "p" ).on( "click", function( event ) {
event.stopImmediatePropagation();
});
$( "p" ).on( "click", function( event ) {
// This function won't be executed
$( this ).css( "background-color", "#f00" );
});
$( "div" ).on( "click", function( event ) {
// This function will be executed
$( this ).css( "background-color", "#f00" );
});
</script>
</body>
</html>