Download : Mastering jQuery / PDF
Download : Mastering jQuery / PDF
Preface
The explosion of JavaScript libraries and frameworks within the front-end development scene has opened up the power of jQuery to a far wider audience than ever before.
What began from a necessity of front-end developers to upgrade JavaScript basic API took a new direction of unified implementation between browsers and to make it more compact in its syntax.
Thanks to this development, it is possible to actually apply optimized scripts now. A script to find all links of a certain CSS class in a document and bind an event to them requires one single line of code instead of ten. Also, jQuery brings to the party its own API, featuring a host of functions, methods
and syntactical peculiarities.
In this Smashing eBook #14: Mastering jQuery, you will learn how to combine JavaScript and jQuery with PHP and, specially, PHP’s GD library to create an image manipulation tool to upload an image, then crop it and finally save the revised version to the server. In addition, you will be able to create your own bookmarklets, which are small JavaScript-powered applications in link form. Typically used to extend the functionality of the browser and to interact with Web services, bookmarklets allow you to post onto your own WordPress or Tumblr blog, submit any selected text to Google's search function, or modify a current CSS code within a browser ― just to cite a few!
Special attention is also given to jQuery plugins, which help save time and streamline development as well as allow programmers to avoid having to build every component from scratch. A good plugin saves countless
development hours, whereas a bad plugin leads to bugs that must be fixed and so takes more of of your time than actually building the component from scratch.
With the help of this eBook, you will get the best hints on how to choose which plugins are really worth considering for your projects and which ones you should avoid.
1. .parent() vs. .parents() vs. .closest()
All three of these methods are concerned with navigating upwards through the DOM, above the element(s) returned by the selector, and matching certain parents or, beyond them, ancestors. But they differ from each other in ways that make them each uniquely useful.
PARENT(SELECTOR)
This simply matches the one immediate parent of the element(s). It can take a selector, which can be useful for matching the parent only in certain situations. For example:
$('span#mySpan').parent().css('background',
'#f90');
$('p').parent('div.large').css('background',
'#f90');
The first line gives the parent of #mySpan. The second does the same for parents of all tags, provided that the parent is a div and has the class large.
Tip: the ability to limit the reach of methods like the one in the second line is a common feature of jQuery.
The majority of DOM manipulation methods allow you to specify a selector in this way, so it’s not unique to parent().
PARENTS(SELECTOR)
This acts in much the same way as parent(), except that it is not restricted to just one level above the matched element(s). That is, it can return multiple ancestors. So, for example:
$('li.nav').parents('li');
//for
each
LI
that
has
the
class
nav,
go
find
all
its
parents/ancestors
that
are
also
LIs
This says that for each that has the class nav, return all its parents/ ancestors that are also
s. This could be useful in a multi-level navigation tree, like the following:......
Preface
The explosion of JavaScript libraries and frameworks within the front-end development scene has opened up the power of jQuery to a far wider audience than ever before.
What began from a necessity of front-end developers to upgrade JavaScript basic API took a new direction of unified implementation between browsers and to make it more compact in its syntax.
Thanks to this development, it is possible to actually apply optimized scripts now. A script to find all links of a certain CSS class in a document and bind an event to them requires one single line of code instead of ten. Also, jQuery brings to the party its own API, featuring a host of functions, methods
and syntactical peculiarities.
In this Smashing eBook #14: Mastering jQuery, you will learn how to combine JavaScript and jQuery with PHP and, specially, PHP’s GD library to create an image manipulation tool to upload an image, then crop it and finally save the revised version to the server. In addition, you will be able to create your own bookmarklets, which are small JavaScript-powered applications in link form. Typically used to extend the functionality of the browser and to interact with Web services, bookmarklets allow you to post onto your own WordPress or Tumblr blog, submit any selected text to Google's search function, or modify a current CSS code within a browser ― just to cite a few!
Special attention is also given to jQuery plugins, which help save time and streamline development as well as allow programmers to avoid having to build every component from scratch. A good plugin saves countless
development hours, whereas a bad plugin leads to bugs that must be fixed and so takes more of of your time than actually building the component from scratch.
With the help of this eBook, you will get the best hints on how to choose which plugins are really worth considering for your projects and which ones you should avoid.
1. .parent() vs. .parents() vs. .closest()
All three of these methods are concerned with navigating upwards through the DOM, above the element(s) returned by the selector, and matching certain parents or, beyond them, ancestors. But they differ from each other in ways that make them each uniquely useful.
PARENT(SELECTOR)
This simply matches the one immediate parent of the element(s). It can take a selector, which can be useful for matching the parent only in certain situations. For example:
$('span#mySpan').parent().css('background',
'#f90');
$('p').parent('div.large').css('background',
'#f90');
The first line gives the parent of #mySpan. The second does the same for parents of all tags, provided that the parent is a div and has the class large.
Tip: the ability to limit the reach of methods like the one in the second line is a common feature of jQuery.
The majority of DOM manipulation methods allow you to specify a selector in this way, so it’s not unique to parent().
PARENTS(SELECTOR)
This acts in much the same way as parent(), except that it is not restricted to just one level above the matched element(s). That is, it can return multiple ancestors. So, for example:
$('li.nav').parents('li');
//for
each
LI
that
has
the
class
nav,
go
find
all
its
parents/ancestors
that
are
also
LIs
This says that for each
Download : Mastering jQuery / PDF
0 commentaires: