Difference between revisions of "Jquery element querys"

From John Freier
Jump to: navigation, search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
These are different ways in JQuery to query for the element(s).
 
These are different ways in JQuery to query for the element(s).
  
_TOC__
+
__TOC__
 
+
Check boxes
+
  $('[type="checkbox"]').click(function(){});
+
  
 +
== Generic Querys ==
  
 
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(){});
 
+
or
 +
  $('.clazz1:not(clazz2)').click(function(){});
  
 
Loop Through
 
Loop Through
Line 21: Line 20:
 
These are a bunch of checkbox querys
 
These are a bunch of checkbox querys
  
 +
 +
Check boxes
 +
  $('[type="checkbox"]').click(function(){});
  
 
Check boxes - get all checked items
 
Check boxes - get all checked items

Latest revision as of 12:29, 31 July 2013

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

Generic Querys

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

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

or

 $('.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

These are a bunch of checkbox querys


Check boxes

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

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'));
 });