What is jQuery?
• Is a free , open Javascript library
• Simplifies the task of creating highly
responsive web pages
• Works across modern browsers
• Abstracts away browser-specific features,
allowing you to concentrate on design
3.
Introduction to Javascript
HTML CSS JavaScript
markup language presentation language scripting language
content presentation behaviour
Java JavaScript
4.
What is ascripting language?
• Can't communicate with OS
• Can't access local files
• Can't directly access database
• Can't access hardware
• Client-side language
• Works on DOM
User's Computer
Web Browser Web Server
Web Page
JavaScript
Python, PHP, ASP.NET,
Ruby on Rails
JavaScript vs jQuery
• Example 1 - Hide an element with id "textbox“
//javascript
document.getElementById('textbox').style.display = "none";
//jQuery
$('#textbox').hide();
• Example 2 - Create a <h1> tag with "my text“
//javascript
var h1 = document.CreateElement("h1");
h1.innerHTML = "my text";
document.getElementsByTagName('body')[0].appendChild(h1);
//jQuery
$('body').append( $("<h1/>").html("my text") ;
8.
Enable jQuery inyour page
• jQuery can be enabled in your page by including
reference to jQuery library file
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
• Introduce a jQuery function by using the below below
given function.
$(document).ready(function(){
//Script goes here
});
OR
$(function(){
//Script goes here
});
9.
Basic selectors
• TagName
document.getElementsByTagName("tagName");
$("tagName") - $("div"), $("p"), $("div"),.....
• Tag ID
document.getElementById("id");
$("#id") - $("#name"), $("#address")
• Tag Class
document.getElementsByClassName("className");
$(".className") - $(".comment"), $(".code")
• To select all elements - $("*")