X

LATEST #JQUERY NEWS

jQuery Snippets: Check/Un-Check All Function


This easy-to-implement jQuery code snippet is super useful, and can be used to create a functionality that will check OR uncheck any checkboxes within a particular fieldeset. So for example, if your HTML looks like this:

<fieldset>
 <div><input type=“checkbox” class=“checkall”>Check All</div>
 <div><input type=“checkbox”>Check Me</div>
 <div><input type=“checkbox”>Check Me</div>
 <div><input type=“checkbox”>Check Me</div>
</fieldset>

Your jQuery code to make the .checkall class actually check all of the checkbox inputs should look something like this:

$(function () {
 $('.checkall').click(function () {
 $(this).parents('fieldset:eq(0)').find(':checkbox').attr('checked', this.checked);
 });
});

With the above code, you can easily add a “Check All” button to any of your fieldset elements.

Recently Published

article image
»

How to Optimize jQuery Code for Better Performance

jQuery is the most popular client side library, in fact almost every ...

article image
»

Using Head.js to Load All Your JavaScript

In the past few years, client side frameworks/libraries have become ...

article image
»

How to Detect Browser Using jQuery

One of the more frustrating parts of creating a new web project is ...

article image
»

Convert Images to Black and White using jQuery

Converting an image to black and white is no longer a manual event. ...

article image
»

How to Use jQuery to Set Textarea Max Length

If you have a textarea field on any of your sites, it might be a good ...

getTable
»

15 Awesome jQuery Table Plugins

Tables are the most preferred way to display data because rows and ...

article image
»

How to Dynamically Open External Links in New Window

Any web developer will probably know that using the ...

article image
»

How to Use jQuery’s .not() Method

jQuery’s .not() method is a method that allows you to return ...

article image
»

jQuery Snippets: How to Add/Remove Classes After Delay

In your projects, there can often be instances of wanting to change ...