I'm trying to check/uncheck a checkbox using jQuery 1.12. This is my code:
$(document).ready(function() {
$('#btn-agree').click(function() {
$('#checkbox-3').prop('checked', true);
});
$('#btn-notagree').click(function() {
$('#checkbox-3').prop('checked', false);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script>
<input type="checkbox" name="agreement" id="checkbox-3" />
<button id="btn-agree">I Agree</button>
<button id="btn-notagree">Cancel</button>
When I click btn-agree
, the function doesn't return any errors, but the checkbox is not checked. console.log($('#checkbox-3').prop('checked');
show true
Can anyone point out what's wrong in my code?
edit I believe the problem comes from somewhere else in my project. please feel free to delete this question.