0

Hello I added an event for when there is a change in my data-value of a div and when some value is typed in my input but for some reason it's not arriving at my console.log inside the event

(function initalize() {
  let seleteced = document.querySelector(
    "div.select-box > div.selected"
  );
  console.log(seleteced.dataset.value)
  setTimeout(function() {
    seleteced.dataset.value = 2
    console.log(seleteced.dataset.value)
  }, 3000);
  [
    document.querySelector("div.select-box > div.selected"),
    document.querySelector("div.input_func > div.material-textfield input"),
  ].forEach((item) => {
    item.addEventListener("change", (event) => {
      console.log("changed");
    });
  });

})();
<div class="custom_select flex">
  <h3 class="textfield_label">
    Selecione a categoria da sua Empresa
  </h3>
  <div class="select-box">
    <div class="options-container"></div>
    <div class="selected">
      Selecione um Tipo de Serviço
    </div>
  </div>
</div>
<div class="input_func">
  <h3 class="textfield_label">
    Quantos Funcionarios têm sua empresa ?
  </h3>
  <div class="material-textfield">
    <input placeholder=" " type="text" />
  </div>
</div>
Barmar
  • 741,623
  • 53
  • 500
  • 612
Ming
  • 1,349
  • 4
  • 13
  • 36
  • 2
    Changing a data value doesn't trigger the `change` event. This event is only triggered on input elements when the user changes the value. – Barmar Jul 14 '20 at 20:10
  • change inner.html call on change event? – Ming Jul 14 '20 at 20:12
  • No. As I said, the `change` event is only triggered when the value of a user input is changed. – Barmar Jul 14 '20 at 20:13
  • 1
    And it has to be changed by the user, it isn't triggered if you assign to `.value` in JS. – Barmar Jul 14 '20 at 20:13

0 Answers0