Changing input border with Javascript

Asked

Viewed 32 times

0

What’s wrong? I need this effect to validate form.

var input = document.getElementByClass("dado");
input.style.border = "1px solid red";

1 answer

3

You’re using the wrong getElementsByClassName. And the return is an array, so it must be accessed by the index:

var input = document.getElementsByClassName("dado");
input[0].style.border = "2px solid red";
<input class="dado" />

Browser other questions tagged

You are not signed in. Login or sign up in order to post.