jQuery is designed to change the way that we write JavaScript. It is actually a new kind of JavaScript library that is fast and concise. jQuery is a lightweight “write less, do more” JavaScript library. jQuery can do the following task.
- Greatly simplifies JavaScript programming.
- Simplifies HTML document traversing.
- Event handling.
- Animating and Ajax interactions for rapid development.
jQuery Features
jQuery is a library of JavaScript Functions. The jQuery library contains the following features:
- HTML element selections
- HTML event functions
- HTML element manipulation
- CSS manipulation
- JavaScript Effects and animations
- HTML DOM traversal and modification
- AJAX
- Utilities
jQuery Syntax
The jQuery syntax is tailor made for selecting HTML elements and performs some action on the element(s).
Basic syntax is: $(selector).action()
- A dollar sign to define jQuery
- A (selector) to “query (or find)” HTML elements
- An jQuery action() to be performed upon the element(s)
Examples:
$(this).hide() – hides current element
$(“p”).hide() – hides all paragraphs
$(“p.test”).hide() – hides all paragraphs with
$(“#test”).hide() – hides the element with
A Simple example code of jQuery
<html>
<head>
<title>jQuery Example by ayub</title>
<script type=”text/javascript” src=”jquery-1.3.2.js”></script>
</head>
<body>
<script type=”text/javascript”>
$(document).ready(function()
{
$(“button”).click(function()
{
$(this).hide()
});
});
</script>
</head>
<button type=”button”>Click me</button>
</body>
</html>
You will get jquery-1.3.2.js from this link http://docs.jquery.com/Downloading_jQuery
This example shows how jQuery hide a button when you click on this button. Here $ sign to define jQuery and button act as selector that select button HTML element. And hide() is an jQuery action() that performed on button HTML element.
jQuery Element Selectors
jQuery uses CSS style selectors to select HTML elements.
$(“p”) selects all <p> elements
$(“p.intro”) selects all <p> elements with.
$(“p#demo”) selects the <p> element with.
jQuery Attribute Selectors
jQuery uses XPath style selectors to select elements with given attributes.
$(“[href]“) select all elements with an href attribute.
$(“[href='#']“) select all elements with an href value=”#”.
$(“[href!='#']“) select all elements with an href attribute<>”#”.
$(“[href$='.jpg']“) select all elements with an href attribute containing “.jpg”.
jQuery CSS Selectors
jQuery CSS selectors can be used to change CSS properties for HTML elements.
$(“p.intro”).css(“background-color”,”yellow”)










Recent Comments