I have pagination that comes with checkbox in first column and each row.
If any of checkbox is checked it will automatic slidedown full wide box from top, I use jquery here is code...
$(':checkbox').change(function() {
// use the :checked selector to find any that are checked
if ($('#checkbox').length) {
$(".checkbox-tools").animate({top: '0px'});
} else {
$('.checkbox-tools').slideUp('slow');
}
});
<!--Cancel print button.-->
$(document).ready(function(){
$("#cancel-chedkbox").click(function(){
$(".checkbox-tools").animate({top: '-450px'});
$('input:checkbox').removeAttr('checked');
});});
This works great when checked on checkbox and slide down.
What if person UNCHECKED and there is no checked in checkbox and I want to automatic slideup full width box instead of person click close button if there is no checked at all.
How can I solve that!
AM
By using jQuery function prop() you can dynamically add this attribute or if present we can change its value i.e. checked=true to make the checkbox checked and checked=false to mark the checkbox unchecked.
$("input:checkbox:not(:checked)") Will get you the unchecked boxes.
To check whether a Checkbox has been checked, in jQuery, you can simply select the element, get its underlying object, instead of the jQuery object ( [0] ) and use the built-in checked property: let isChecked = $('#takenBefore')[0]. checked console. log(isChecked);
We can check the status of a radio button by using the :checked jQuery selector together with the jQuery function is . For example: $('#el').is(':checked') . It is exactly the same method we use to check when a checkbox is checked using jQuery.
For uncheck checkboxes use:
$('input:checkbox').prop('checked', false)
To check checkboxes use:
$('input:checkbox').is(':checked')
To count checked checkboxes use:
$('input:checked').length
It's similar post on: checking if a checkbox is checked?
In Your code, all checkboxes have ID #checkbox
- ID have to be unique, here You have working code http://jsfiddle.net/s8Xju/1/:
$(':checkbox').change(function() {
// use the :checked selector to find any that are checked
if ($(':checkbox:checked').length > 0) {
$(".checkbox-tools").animate({top: '200px'});
} else {
$('.checkbox-tools').animate({top: '-450px'});
}
});
To check a checkbox:
$('input:checkbox').prop('checked', true)
To uncheck a checkbox:
$('input:checkbox').prop('checked', false)
To check whether particular checkbox is checked or not:
$('input:checkbox').is(':checked')
This statement returns true if checked and returns false if unchecked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With