Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
JavaScript: Chrome and Safari trigger no mouse events when already-selected <option> of <select> is clicked

I'm trying to respond when the user re-clicks the currently-selected <option> in a <select>. Current desktop FF (v95.0.2) fires mousedown, mouseup, and click on the <option> element itself, and everything captures down and bubbles up through the entire HTMLDocument hierarchy, including the containing window.

In the same situation, current desktop Chrome (96.0.4664.110) and Safari (14.1.2) don't seem to fire any events at all.

<html lang="en" id="thehtml">

<head>
</head>

<body id="thebody">
  <select id="theselect">
    <option id="option1" value="1">one</option>
    <option id="option2" value="2">two</option>
  </select>
</body>

<script>
  function logEvent(ev) {
    console.log(
      ev.type +
      '   target: ' + (ev.target.localName ? `${ev.target.localName} #${ev.target.id}` : `(${ev.target.constructor.name})`) +
      '   this: ' + (this.localName ? `${this.localName} #${this.id}` : `(${this.constructor.name})`)
    );
  }

  var eventList = ['change', 'click', 'dblclick', 'input', 'mousedown', 'mouseup'];
  var elementList = ['thehtml', 'thebody', 'theselect', 'option1', 'option2'];

  for (let ev of eventList) {
    window.addEventListener(ev, logEvent, true); // capture
    window.addEventListener(ev, logEvent, false); // bubble

    document.addEventListener(ev, logEvent, true); // capture
    document.addEventListener(ev, logEvent, false); // bubble

    for (let id of elementList) {
      document.getElementById(id).addEventListener(ev, logEvent, true); // capture
      document.getElementById(id).addEventListener(ev, logEvent, false); // bubble
    }
  }
</script>

</html>

Is there any way on Chrome or Safari to detect the user clicking the mouse on the currently-selected <option>?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda