Professional Documents
Culture Documents
Jquery Foundations
Jquery Foundations
WHAT IS JQUERY?
• jQuery is an Open-Source JavaScript framework that simplifies cross-
browser client side scripting.
• jQuery takes a lot of common tasks that require many lines of JavaScript
code to accomplish, and wraps them into methods that you can call with a
single line of code.
• The jQuery library contains the following features:
1. HTML/DOM manipulation
2. CSS manipulation
3. HTML event methods
4. Effects and animations
5. AJAX
6. Utilities
INCLUDING JQUERY IN YOUR PAGES
• Including jquery on your web-page is direct use hosted jquery library files, both
Google and Microsoft host jQuery library or either link to a locally hosted version of
the library .
• Using a third-party content delivery network (CDN) is advantageous for several
reasons.
1. It reduces the load from your server.
2. It saves bandwidth.
3. When any user visit on other website it save in browser, as a result
next time easily load.
• A disadvantage to the third-party CDN is that your jQuery will fail if the
third party host fails, although that is unlikely given the mission-critical
demands of large companies like Google and Microsoft
jQuery loading using a CDN and a local fail-safe if the
CDN is offline
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
window.jQuery ||
document.write('<script src="/jquery-1.9.1.min.js"><\/script>');
</script>
<head> <script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.
min.js"></script> </head>
JQUERY SELECTORS
• jQuery selectors are used to select HTML elements based on their name, id,
classes, types, attributes, values of attributes and much more. It's based on the
existing CSS Selectors.
• All selectors in jQuery start with the dollar sign and parentheses: $().
• The selectors always return arrays of results, rather than a single object
Basic selectors
■ $("*") Universal selector matches all elements (and is slow).
■ $("tag") Element selector matches all elements with the given element name.
■ $(".class") Class selector matches all elements with the given CSS class.
Pseudo-Element Selector
Pseudo-element selectors allow you to append to any selector using
the colon and one of :link, :visited, :focus, :hover, :active, :checked,
:first-child, :first-line, and :first-letter.
Contextual Selectors
• These selectors allowed you to specify elements with certain relationships
to one another in your CSS.
• These relationships included descendant (space), child (>), adjacent sibling
(+), and general sibling (~). To select all elements inside of
elements you would write var para = $("div p")
Content Filters
• The content filter is the only jQuery selector that allows you to append filters to
all of the selectors and match a particular pattern.
• select elements that have a particular child using :has(), have no children using
:empty, or match a particular piece of text with :contains()
Form selector
JQUERY ATTRIBUTES
Some of the most basic components we can manipulate when it comes to DOM elements
are the properties and attributes assigned to those elements.
Most of these attributes are available through JavaScript as DOM node properties. Some
of the more common properties are −
• className
•tagName
•id
•href
•title
•rel
•src
Get Attribute Value
The attr() method can be used to either fetch the value of an attribute from the first
element in the matched set or set attribute values onto all matched elements.
The attr(name, value) method can be used to set the named attribute onto all
elements in the wrapped set using the passed value.
Applying Styles
The addClass( classes ) method can be used to apply defined style sheets onto all
the matched elements. You can specify multiple classes separated by space.