Changing input border with Javascript

0

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

var input = document.getElementByClass("dado");
input.style.border = "1px solid red";
    
asked by anonymous 21.12.2016 / 18:30

1 answer

3

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

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