I am trying to get the elements in the paragraph class 'answer', the font actually, to change colors by clicking a button. I am not trying to change the background color as in other Javascript questions on stack exchange, but the characters of the element, The font color. Also, I need to use this over and over again, so I would rather use the class functions as opposed to the id. I want the font color of the characters to white for the hideFunction, which will match the background and 'hide' the letters. In the showFunction, I want the paragraph color to be black, which against a white background will boldly show the characters.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Book Title</title>
<script>
function showFunction() {
var x = document.getElementsByClassName("answer");
x.style.color = "black";
}
function hideFunction() {
var x = document.getElementsByClassName("answer");
x.style.color = "white";
}
</script>
<style>
</style>
</head>
<body>
<h1>Book Title </h1>
<p class="question"> This is a question.
</p>
<p class="answer">This is an answer.
</p>
<br />
<div>
<label>Check Answer:</label>
<button onclick="showFunction()">Show Answer</button>
<button onclick="hideFunction()">Hide Answer</button>
</div>
</body>
</html>