Академический Документы
Профессиональный Документы
Культура Документы
Features of jQuery
It works on all browsers
It is fast and extensible
Make look UI stunning
Allows to access elements in the
document
Easily apply CSS
Perform animation in better way
Ajax Interaction made easy
Change documents content easily
Event handling made easy
Big pool of reusable plugins for
various functionalities
jQuery Versions
The uncompressed .js file is easy to read and modify, but
it's around 190kb in size (at the time of writing).
The minified .js file has all comments, whitespace, and
other unnecessary characters removed from the file,
squeezing the whole library into a mere 23kb (ie;
lightweight).
CDN(Content Distribution/Delivery
Network)
large distributed system of servers deployed in multiple data
centers in the Internet. The goal of a CDN is to serve content to endusers with high availability and high performance.
Advantages of using CDN.
Reduce Load: It reduces the load on your web server as it
downloads from Google server's.
Caching: The most important benefit is caching. If any previously
visited site by user is using jQuery from any CDN then the cached
version will be used. It will not be downloaded again.
Serves fast: As CDN has dozen's of different servers around the
web and it will download the jQuery from whichever server is closer
to the user.
Parallel Downloading: As the jQuery js file is on a separate
domain, modern browsers will download the script in parallel with
scripts on your domain.
de
gdfg
Output
$(document).ready()function.
an entry pointand gets called as soon as DOM is loaded. You need to
place all your jQuery code within this function. JavaScript developers
can think of window.onload() being similar to $(document).ready(). But
it is different
Running Code Unobtrusively When the DOM is Ready
"document ready" handler. This accomplishes two things: First, it
ensures that
the code does not run until the DOM is ready. This confirms that any
elements being accessed are actually in existence,so the script won't
return any errors. Second, this ensures that your code is unobtrusive.
That is, it's separated from content (XHTML) and presentation
(CSS).
Change Contents
To Find / search
through our HTML
We need to
understand how
our browser
Organizes the
HTML it receives
DOM Structure
Jquery to Rescue
1. Get Element -
WHY Document.ready()
Document.ready()
window.onload() vs $(document).ready()
Selecting by ELEMENT
Selecting by ID
Selecting by Class
Selecting Descendants
jQuery supports the use of all CSS selectors, even those in CSS3. Here are some examples of alternate
selectors
$("p > a"); // selects anchors that are direct children of paragraphs
$("input[type=text]"); // selects inputs that have specified type
$("a:first"); // selects the first anchor on the page
$("p:odd"); // selects all odd numbered paragraphs
$("li:first-child"); // every list item that's first child in a list.
jQuery also allows the use of its own custom selectors. Here are some examples:
Contd
DOM Traversing
You can also check to see if a selected element has a particular CSS class, and then
run some code if it does. You would check this using an if statement. Here is an
example:
if ($("#myElement").hasClass("content")) {
// do something here
}
N.B :- You could also check a set of elements (instead of just one), and the result would
return "true" if any one of the elements contained the class.
If you don't want to access the HTML, but only want the text of an element:
var myElementHTML = $("#myElement").text();
// variable contains all text (excluding HTML) inside #myElement
Using similar syntax to the above two examples, you can change the HTML or text content of a specified
element:
$("#myElement").html("<p>This is the new content.</p>");
// content inside #myElement will be replaced with that specified
$("#myElement").text("This is the new content.");
// text content will be replaced with that specified
To append content to an element:
$("#myElement").append("<p>This is the new content.</p>");
// keeps content intact, and adds the new content to the end
$("p").append("<p>This is the new content.</p>");
// add the same content to all paragraphs
jQuery also offers use of the commands appendTo(), prepend(), prependTo(), before(), insertBefore(), after(),
insertAfter(),