jQuery

Node.js & JavaScript Package: jQuery Library

Utilities

jQuery.each()

var obj = {
  "flammable": "inflammable",
  "duh": "no duh"
};

$.each( obj, function( key, value ) {
  console.log( key + ": " + value );
});

jQuery.find()

Search for a children element.

$(row).find('.children_name').text('hi');

Form

Checkbox

// Get all checked checkbox
$('.myCheckBox:checked');

// Set checkbox property
$checkbox.prop('checked', true);
$checkbox.prop('checked', false);
// Toggle checkbox
$checkbox.prop('checked', !$checkbox.prop('checked'));

// is checked
$('.myCheckbox').is(':checked');

Select

Selected option text

// Selected value
$("#mySelect").val();

// Selected option text
$("#mySelect option:selected").text();

Request

Request with JSON content type & JSON payload

var post_data = {
  'name': 'KJ'
};

var post_data_json = JSON.stringify(post_data);
 
$.ajax({
    url: '/some/api',
    data: post_data_json,
    type: "POST",
    dataType: "json",
    contentType: "application/json;charset=utf-8",
    success: function(return_data){
        console.log(return_data);
    },
    error: function(xhr, ajax_options, thrown_error){
        console.log(xhr.status);
        console.log(thrown_error);
    }
});

Reference