Whenever I click on the resetBtn, it triggers the Flow.reset function regardless of whether the gameboard has child elements. Am I using the hasChildNodes() method incorrectly?
const resetBtn = document.querySelector('#reset');
resetBtn.addEventListener('click', () => {
if (document.getElementById('gameboard').hasChildNodes()) {
Flow.reset();
}
else {
return;
}
});
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" type="text/css" href="styles.css">
<script src="main.js" type="text/javascript"></script>
<title>Tic Tac Toe</title>
</head>
<body>
<div class="mainContainer">
<h1 class="header">Tic Tac Toe</h1>
<div class="gameBoard" id="gameboard">
</div>
<div class="names-container">
<input type="text" id="player1" placeholder="Player 1 Name">
<input type="text" id="player2" placeholder="Player 2 Name">
</div>
<div class="buttonsContainer">
<button class="startBtn" id="start" class="name-field">Start</button>
<button class="resetBtn" id="reset" class="name-field">Reset</button>
</div>
<div class="message"></div>
<div class="resultsContainer"></div>
</div>
</body>
</html>