jQuery 101: Basic examples

Simple examples of selecting based on class and id of elements, binding a function to the click event, and changing css through jQuery.

by kazu69

HTML

<div id='hoge'>0</div>

JavaScript

$(function() {
var get = function() {
return $.ajax({url: '/echo/json/'});
}

var update= function(id, res) {
  if (res === null) {
     // $('#' + id).html(1111)
     $d.html(1111)
  }
}
$d = $('#hoge');
get.call().done(function(res) {
  update('hoge', res)
})
});