Home > Mobile >  why my date is not displayed the value altough the value is changed?
why my date is not displayed the value altough the value is changed?

Time:02-20

Why I dont see my date if I change the value ?

<button >Button</button>
<input type="date" value=""  />

<script>
  button.addEventListener('click', () => {
    const dateS = document.querySelector('.dt');
    dateS.value = '2022-02-02';
  });
</script>

it shows me this:

tt.mm.jjjj

the value is changed but not displayed

CodePudding user response:

You need to define your button element before using it. const button = document.querySelector('.btn');

check the code below.

<button >Button</button>
<input type="date" value=""  />

<script>
  const button = document.querySelector('.btn');

  button.addEventListener('click', () => {
    const dateS = document.querySelector('.dt');
    dateS.value = '2022-02-02';
  });
</script>

  • Related