Difference between revisions of "Jquery element querys"

From John Freier
Jump to: navigation, search
Line 7: Line 7:
 
Not - When getting a group of items, this will exclude certain ones.
 
Not - When getting a group of items, this will exclude certain ones.
 
   $('.clazz1').not('.clazz2').click(function(){});
 
   $('.clazz1').not('.clazz2').click(function(){});
 +
  
 
Loop Through
 
Loop Through
Line 13: Line 14:
 
       $(this).val();
 
       $(this).val();
 
  }
 
  }
 +
 +
Check boxes - get all checked items
 +
This example loops through all the check boxes and gets all checked items
 +
$('#formBatchPublisher input:checkbox:checked').each(function(){
 +
      alert($(this).attr('id'));
 +
  });

Revision as of 11:05, 26 September 2011

These are different ways in JQuery to query for the element(s).

Check boxes

 $('[type="checkbox"]').click(function(){});


Not - When getting a group of items, this will exclude certain ones.

 $('.clazz1').not('.clazz2').click(function(){});


Loop Through This example loops through all the input elements in a form with the id = "formid"

$('#formid input').each(function(){
     $(this).val();
}

Check boxes - get all checked items This example loops through all the check boxes and gets all checked items

$('#formBatchPublisher input:checkbox:checked').each(function(){
     alert($(this).attr('id'));
 });