Jquery
Jquery
jquery
SUHAIB REHMAN
TRAINER
jQuery is a lightweight,
"write less, do more", JavaScript library.
The purpose of jQuery is to make it much easier to use JavaScript on your website.
Include jquery Visit:” https://jquery.com/download/”
To minimize the use of js and css
document.querySelector(“h1”)
$(“h1”)
document.querySelectorAll(“h1”)
$(“h1”)
Adding CSS
$("h1").css("color","red")
Console.log($("h1").css("color"))
Retuns the current value
Adding CSS
$("h1").addClass(“menu”)
$("h1").removeClass(“menu”)
$("h1"). hasClass(“menu”)
Change text
$(“button").html(“<em>click</em”)
Click
$(“button").text(“<em>click</em”)
<em>Click</em>
Manipulate Attributes
$(“img").attr(“src”)
Get attribute
$(“a").attr(“href”,”http://www.google.com”)
set attribute
Add Event Listener
$(“h1").click(function(){
$(“h1").css(“color”,” purple”)
})
$(“button").click(function(){
$(“h1").css(“color”,” purple”)
})
Add Event Listener
$(“h1").on(“keypress”,function(event){
$(“h1"). text(event.key)
})
$(“button").click(function(){
$(“h1").css(“color”,” purple”)
})
Add Elements in jquery
$(“h1").before(““<button>New</button>”)
<button>New</button> <h1>hello</h1>
$(“h1").after(““<button>New</button>”)
<h1>hello</h1> <button>New</button>
$(“h1").append(““<button>New</button>”)
<h1>hello <button>New</button> </h1>
$(“h1").prepend(““<button>New</button>”)
<h1> <button>New</button> hello </h1>
Jquery Effects
$("button").click(function(){
$("div").animate({
left: '250px',
height: '+=150px',
width: '+=150px'
});
});
Call back function use
$(document).ready(function(){
$("button").click(function(){
$("p").hide("slow",function(){
alert("The paragraph is now hidden");
});
});
});
Jquery Traversing
With jQuery you can traverse up the DOM tree to find ancestors of an element.
2. parents() This method only traverse a single level up the DOM tree.
3. parentsUntil()
The parents() method returns all ancestor elements of the
selected element, all the way up to the document's root
element (<html>).
The parentsUntil() method returns all ancestor elements
between two given arguments.
parent
parents
With jQuery you can traverse up the DOM tree to find ancestors of an element.
1. children()
2. find()
The children() method returns all direct children of the selected element.
This method only traverses a single level down the DOM tree.