I'm trying to make form validation but I think my button doesn't work. I did this with paragraph which has "visibility: hidden" style and I want to change it to "visibility: visible" on button click if there is nothing typed in input fields. What can I do to fix it? Here is JS code:
document.querySelector("cta-btn").addEventListener("click", function() {
let name = document.getElementsByClassName("first-name").value;
if (name == "") {
document.getElementsByClassName("name-error").style.visibility = "visible";
document.getElementsByClassName("first-name").style.border = "1px solid red"
}
});