I'm a beginner in jQuery and trying to have a bit of fun. I'm trying to make a button that will change the background of the page when clicked, as well as change the text of the button. I only need two scenarios: - if the button says "1", change the button to "2" and the background to black; - if the button says "2", change the button to "1" and the background to white;
My code works for the first click but you can't click more than once.
What did I do wrong? Thanks for your time.
This is my HTML
<body>
<button id="lumiere">1</button>
</body>
This is my script
$(function() {
$('#lumiere').bind('click', function(event) {
if ($('#lumiere:contains("1")')) {
$('body').css('background-color', "black")
$('#lumiere').html('2')
}
else if ($('#lumiere:contains("2")')) {
$('body').css('background-color', "white")
$('#lumiere').html('1')
}
}
);
}
);