JQuery Quick Tip: Loop through each visible object


I need to loop through some checkboxes identified by a class.

There are lots of “try this” in the forums, so I wanted to post what worked in jquery 1.11.1

This iterates through objects of a class selector that are visible and concatenates their ID to a string.

….because I wanted the example to be simple,  that’s why.


$('.aacheck').filter(':visible').each(function(i,o) {    //i: iteration  o: object

chdept += '~' + $(o).attr('id');


If you need to check multiple conditions (like checkboxes that are visible AND checked)…

$('.aacheck').filter(':visible').filter(':checked').each(function(i,o) {    //i: iteration  o: object

chdept += '~' + $(o).attr('id');




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s