Using Array in jQuery

Submit


HTML

						<ul id="list">
							<li><label><input value="Advertising" type="checkbox" /> Advertising</label></li>
							<li><label><input value="Art" type="checkbox"  /> Art</label></li>
							<li><label><input value="Automotive" type="checkbox" /> Automotive</label></li>
							<li><label><input value="Business" type="checkbox" /> Business</label></li>
							<li><label><input value="Celebrity" type="checkbox" /> Celebrity</label></li>
							<li><label><input value="Comedian" type="checkbox" /> Comedian</label></li>
							<li><label><input value="Education" type="checkbox" /> Education</label></li>
							<li><label><input value="Entertainment" type="checkbox" /> Entertainment</label></li>
							<li><label><input value="Family" type="checkbox" /> Family</label></li>
							<li><label><input value="Fashion" type="checkbox" /> Fashion</label></li>
							<li><label><input value="Film" type="checkbox" /> Film</label></li>			
						</ul> 
					

jQuery Code

						$(document).ready(function() {					 
							$("input").click(function () {
								$(this).toggleClass('selected');					 
							});		
							
							// on submit check selected class for a value
							$(".submit").click(function () {					 
								var itemsarray = [];					 
								$("#list li .selected").each(function () {					 				 
									var items = $(this).attr('value');
									itemsarray.push(items);					 
								});					 
								// this is where we could process the array or POST it with AJAX
								alert(itemsarray);
							});					 
						});	
					

jQuery Code 2

						$(document).ready(function() {		
							$(".submit").click(function () {					 
								var itemsarray = [];					 
								$("#list li :checked").each(function () {					 				 
									var items = $(this).attr('value');
									itemsarray.push(items);					 
								});					 
								// this is where we could process the array or POST it with AJAX
								alert(itemsarray);
							});					 
						});