Professional Documents
Culture Documents
Introduction :: Introduction
to jQuery
Introduction to jQuery
- jQuery is a fast and concise JavaScript Library created by John Resig in 2006 with a nice motto
− Write less, do more.
- jQuery simplifies HTML document traversing, event handling, animating, and Ajax interactions for
rapid web development.
- jQuery is a JavaScript toolkit designed to simplify various tasks by writing less code.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
You can use any of these two ways but MAX CDN Server is more Faster than Local Server.
Introduction :: Basic
Syntax
.js
$(document).ready(function(){
$("#btn").click(function(){
alert("Yes, its open the window");
});
$(".btn").click(function(){
$(".btn").hide("5000");
});
});
Selectors :: Introduction
to jQuery Selectors
jQuery Selectors
jQuery Selectors allows you to select HTML elements. Through
Types of selectors:
Element Selectors
.js
$(document).ready(function(){
$("h2").click(function(){
.html
$("p").fadeToggle(1000); <h2>Element Selector</h2>
$("p").hide();
Selectors :: jQuery Even | Odd | First
| Last & Nth Element Selectors
.css
Even | Odd | First | Last & Nth Element Selectors .odd{
background: orange;
padding: 10px;
.html }
.js <ul class="list-unstyled"> .even{
background: skyblue;
$(document).ready(function(){ <li>Home</li> padding: 10px;
<li>About</li> }
$("li:odd").addClass("odd");
<li>Photo Gallery</li> .first{
$("li:even").addClass("even"); <li>Project</li> background: #b2dba1;
padding: 10px;
<li>Webmail</li> }
$("li:first").addClass("first");
<li>Company Profile</li> .last{
$("li:last").addClass("last"); background: #f2dede;
<li>Contact Us</li> padding: 10px;
}
$("li:eq(3)").addClass("nth"); // Index equal to n </ul>
.nth{
background: maroon;
});
color: oldlace;
padding: 10px;
}
Selectors :: jQuery This |
.html
This Selectors Header | Not Selectors
.js <p>This is Dolon</p>
});; .html
<h1>This is Dolon</h1>
<h2>This is Rahat</h2>
Header Selectors
<h3>This is Ridoy</h3>
.js
<h4>This is Momo</h4>
$(document).ready(function(){
<h5>This is Eva</h5>
$(":header").fadeOut(3000);
<h6>This is You</h6>
});
.html
<h1>This is Dolon</h1>
Not Selectors <h1>This is Rahat</h1>
.js <h1>This is Eva</h1>
$(document).ready(function(){ <h1>This is Ridoy</h1>
$("h1:not(h1:eq(5))").fadeOut(3000); <h1>This is Momo</h1>
}); <h1>This is You</h1>
Contains Selectors Selectors :: jQuery Contains |
.js Attribute| Form field Selectors
$(document).ready(function(){
$("h3").hide();
.html
$("#show").click(function(){
<button type="button" id="show" class="btn btn-danger">Show Student
$("h3:contains('Dolon')").fadeIn(2000);
Performance</button>
});
<h3>07 Dolon Willes</h3>
});
<h3>05 Rahat Willes</h3>
Attribute Selectors <h3>100 Dolon Final Math</h3>
.js <h3>100 Rahat Final Math</h3>
$(document).ready(function(){
.html
<a href="#" title="GIS" class="well well-sm">Grameen IT
$("a[title='TW']").fadeOut(3000);
Solution</a>
});
<a href="#" title="FB" class="well well-sm">Facebook</a>
<a href="#" title="TW" class="well well-sm">Twitter</a>
Form Field Selectors .html
.css
.js <form > .fn{
$(document).ready(function(){ First Name : <input type="text" name="firstname" > 2px solid red;
border:
}
$(":input:password").addClass("fn"); Password : <input type="password" name="password">
}); </form>