Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 68 lines (60 sloc) 3.92 KB
---------------------------------------------------------------------------------------------
Syntax Description
---------------------------------------------------------------------------------------------
$(this) Current HTML element
$("p") All <p> elements
$("p.intro") All <p> elements with class="intro"
$("p#intro") All <p> elements with id="intro"
$("p#intro:first") The first <p> element with id="intro"
$(".intro") All elements with class="intro"
$("#intro") The first element with id="intro"
$("ul li:first") The first <li> element of each <ul>
$("[href$='.jpg']") All elements with an href attribute that ends with ".jpg"
$("div#intro .head") All elements with class="head" inside a <div> element with id="intro"
---------------------------------------------------------------------------------------------
jQuery Events
Here are some examples of event methods in jQuery:
Event Method Description
$(document).ready(function) Binds a function to the ready event of a document(when the document is finished loading)
$(selector).click(function) Triggers, or binds a function to the click event of selected elements
$(selector).dblclick(function) Triggers, or binds a function to the double click event of selected elements
$(selector).focus(function) Triggers, or binds a function to the focus event of selected elements
$(selector).mouseover(function) Triggers, or binds a function to the mouseover event of selected elements
---------------------------------------------------------------------------------------------
jQuery Effects
Here are some examples of effect functions in jQuery:
Function Description
$(selector).hide() Hide selected elements
$(selector).show() Show selected elements
$(selector).toggle() Toggle (between hide and show) selected elements
$(selector).slideDown() Slide-down (show) selected elements
$(selector).slideUp() Slide-up (hide) selected elements
$(selector).slideToggle() Toggle slide-up and slide-down of selected elements
$(selector).fadeIn() Fade in selected elements
$(selector).fadeOut() Fade out selected elements
$(selector).fadeTo() Fade out selected elements to a given opacity
$(selector).animate() Run a custom animation on selected elements
---------------------------------------------------------------------------------------------
$(selector).html(content)
The html() method changes the contents (innerHTML) of matching HTML elements.
---------------------------------------------------------------------------------------------
jQuery HTML Manipulation Methods From This Page:
Function Description
$(selector).html(content) Changes the (inner) HTML of selected elements
$(selector).append(content) Appends content to the (inner) HTML of selected elements
$(selector).after(content) Adds HTML after selected elements
---------------------------------------------------------------------------------------------
jQuery AJAX Methods From This Page:
Request Description
$(selector).load(url,data,callback) Load remote data into selected elements
$.ajax(options) Load remote data into an XMLHttpRequest object
---------------------------------------------------------------------------------------------
All modern browsers support the XMLHttpRequest object (IE5 and IE6 uses an ActiveXObject).
---------------------------------------------------------------------------------------------
GET or POST?
GET is simpler and faster than POST, and can be used in most cases.
However, always use POST requests when:
A cached file is not an option (update a file or database on the server)
Sending a large amount of data to the server (POST has no size limitations)
Sending user input (which can contain unknown characters), POST is more robust and secure than GET
---------------------------------------------------------------------------------------------