jquery iterate checked checkboxes tutorial

Hello, This post is a real quick one that I wanted to share, every time try to iterate through checked checkboxes I have to refer it from my notes. Because I keep on forgetting  required selector. But this post will be my reference from now on too on what I try to achieve. Ok so lets go ahead and check out how to do it. There are many ways you can do it. I'll show you a few techniques. The Markup Consider this markup. All our examples will be based on this   Technique 1 Using selector :checked The above code will select all the checkboxes that are checked and will append string "checked" to each of them. Now you can limit your selection to a parent container too, in our case batch1 and batch2 are two DIVs with different checkboxes. To limit the scope we will change the above to That will look for checkboxes only under DIV with ID batch1 Technique 2 or  Pretty much the same thing except that we are getting a Collection object for all checkboxes and we are making sure with if statement the ones that are checked to apply our action to. Once again you can limit the scope to children of a parent by creating suitable query for jQuery to follow. Technique 3 Here we are using selector :checkbox which is shorthand to input[type=checkbox] As you notice that we are limiting our scope in above example to checkboxes under batch2 container only Demo Above would make more sense if we can check out this demo page by me http://jaspreetchahal.org/examples/jquery-examples/jquery-checkbox-iteration-demo.html#     I hope that this helps you. In case you would like to leave a comment for me or would like to add another technique please do so by leaving your comments. Cheers,       … [Read more...]