The correct answer is C .
The typing errors in the options should be corrected as follows:
event.stopPropagation();
The stopPropagation() method is used to stop an event from continuing through the DOM event propagation path.
A click event normally goes through these phases:
Capturing phase → Target phase → Bubbling phase
Because the event listener is attached to the button:
el.addEventListener( " click " , printMessage, false);
the function printMessage receives the click event when the button is clicked. To stop the event from bubbling up to parent elements, the event object should be accepted as a parameter and stopPropagation() should be called inside the event handler.
Corrected code:
< html >
< body >
< div id= " logo " > Hello Logo! < /div >
< button id= " test " > Click me < /button >
< /body >
< script >
function printMessage(event) {
event.stopPropagation();
console.log( ' This is a test message ' );
}
let el = document.getElementById( ' test ' );
el.addEventListener( " click " , printMessage, false);
< /script >
< /html >
Why this is correct:
event.stopPropagation();
prevents the click event from moving upward to ancestor elements after the button’s handler runs.
Why the other options are incorrect:
A and B are incorrect because removeEventListener() is used to remove a previously registered event listener. It does not stop event bubbling for the current event.
D is incorrect because stopPropagation() should be called inside the active event handler that receives the event object. In this case, that function is:
printMessage(event)
Therefore, the verified answer is C .
Submit