Posted By

mracoker on 01/25/10


Tagged

jquery common sheet cheat


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

cro1979


Jquery Cheat Sheet


 / Published in: JavaScript
 

  1. $(document).ready(function() {
  2. //start here
  3. });
  4.  
  5. //get element by id
  6. $('#something')
  7.  
  8. //get element by class
  9. $('.something')
  10.  
  11. //get input that by name in a element with id and set its value
  12. $(':[name=txtCardNumber]', '#somediv').val('');
  13.  
  14. //get elements that have some class in some element that is not visible
  15. $('.someclass', '#someid').not(':visible')
  16.  
  17. //get the selected value in a drop down
  18. $('option:selected', '#someid').val();
  19.  
  20. //get the checked value of a checkbox in some element
  21. 1) $('input[name=someCheckBox]', '#someid').attr('checked');
  22. 2) $('#somecheckbox').is(':checked')
  23.  
  24. //set the value of some asp.net control
  25. $('#<%= aspnet_object.ClientID %>').val(newZip);
  26.  
  27. //simple function to check all checkboxes
  28. //<input type="checkbox" onclick="InterestOptionAll_OnChange(this);" /><b>Check All</b>
  29. function InterestOptionAll_OnChange(obj) {
  30. var isChecked = $(obj).is(':checked');
  31.  
  32. $('input:checkbox', '.interestOptions').each( function(){
  33. this.checked = isChecked;
  34. });
  35. }

Report this snippet  

You need to login to post a comment.