button in clickable paragraph

browsereventpropagationstop ⟩ example ⟩ button in paragraph

if the button is right-clicked, the event will stop propagation to its enclosing paragraph.

const {log} = console

// ⭐️ import
import { $ } from './js/ext/Node_ext.js'; // Node extension
// --------------------------------------------------------------------

// ⭐️ event handlers

// <button>
$('button').onmousedown = function(e) {
    log(`🐭`);
    // ⭐️ if right-clicked, stop event propagation.
    if (e.button === 2) e.stopPropagation();
};

// <p>
$('p').onmousedown = function() {
    log(`🅿️`);
};

Last updated