I'm getting this error "app_copy.js:13 Uncaught TypeError: Cannot read property 'remove' of undefined" and am not sure why. When you click on the first button I want those buttons removed and two hidden buttons to show. Why am I getting this error when I click on the first button? It works if I use document.querySelector and remove a single one but not if I use document.querySelectorAll like I'm trying to do here. Thanks!
Codepen: http://codepen.io/abharms/pen/BKvYvL
HTML
<div class="wrapper">
<a class="numberButtons first" href="#">1</a>
<a class="numberButtons second" href="#">2</a>
<a class="numberButtons third" href="#">3</a>
<a class="yesNo hide" href="#">Yes</a>
<a class="yesNo hide" href="#">No</a>
</div>
CSS
body {
background-color: #74c7d5;
}
.wrapper {
text-align: center;
margin-top: 200px;
}
.wrapper a {
text-decoration: none;
padding: 10px 15px 10px 15px;
margin: 10px;
border: 1px solid white;
color: #9965a8;
border-radius: 5px;
}
.wrapper a:hover {
background-color: white;
color: #74c7d5;
}
.hide {
display: none;
}
JavaScript
var numberButtons = document.querySelectorAll(".numberButtons");
var yesNo = document.querySelectorAll(".yesNo");
var first = document.querySelector(".first");
var second = document.querySelector(".second");
var third = document.querySelector(".third");
function numberButtonsLoop() {
for(var i = 0; i < numberButtons.length; i++)
numberButtons[i].addEventListener("click", function(){
var clickedOption = this;
if(clickedOption === first) {
yesNo.classList.remove("yesNo");
numberbuttons.classList.add("hide");
}
});
};
numberButtonsLoop();