Having trouble with a button click issue. In the following code, when the button is clicked, it checks if the text on the button is "day". If so, it changes the background-color of the body to red and updates the button text to "night". I am struggling with making the body background color revert and changing the button text back to "day" when the button with "night" text is clicked.
var buttonText = $('button').text();
$('button').click(function() {
if (buttonText == 'day') {
$('body').css({
'background': 'red'
})
$('button').text('night');
} else if (buttonText == 'night') {
$('body').css({
'background': 'yellow'
})
}
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
<p>velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<button type="button" name="button">day</button>