Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery checkbox is unchecked

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

like image 944
user3417953 Avatar asked Mar 20 '14 21:03

user3417953


People also ask

Is unchecked checkbox jQuery?

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.

How get checkbox is unchecked?

$("input:checkbox:not(:checked)") Will get you the unchecked boxes.

How check if checkbox is checked jQuery?

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);

How do I check if a Radiobutton is selected in jQuery?

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.


2 Answers

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?

UPDATE:

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'});
    }
 });
like image 181
Laguna Web Design Avatar answered Sep 21 '22 21:09

Laguna Web Design


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.

like image 25
Rajesh Grandhi Avatar answered Sep 21 '22 21:09

Rajesh Grandhi