Techiio-author
Started by Ronald RauheSep 10, 2021

Open
why some operations does not apply to an element with two css classes?

1 VIEWES 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 1 VIEWES SHARE

i have two input elements and a button as follow:

<input class="close-acc-usr opt-in" type="text" name="closeAccUsr" />
<input class="close-acc-pin opt-in" type="number" name="closeAccPin" />
<button class="opt-btn close-btn">→</button>

in js I want to by clicking on the button, both input element contents become clear, so I write this line of code in the button event handler function:

document.querySelector('.opt-in').value = '';

but it does not work!! in fact if I write above code for '.close-acc-pin' and '.close-acc-usr' class names instead of .opt-in it works! but why with '.opt-in' it does not work?

1 Replies

Techiio-commentatorMotiar Rahaman replied 8 days ago0 likes0 dislikes

If you use querySelectorAll then may be its working .You can try like this

let btn = document.querySelector('.opt-btn')
btn.addEventListener('click', function() {
let inputs = document.querySelectorAll('.opt-in');
inputs.forEach(input => input.value = '')
})

You must be Logged in to reply
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance