J Query
J Query
What is jQuery?
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.
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.
jQuery also simplifies a lot of the complicated things from JavaScript,
like AJAX calls and DOM manipulation.
The jQuery library contains the following features:
HTML/DOM manipulation
CSS manipulation
HTML event methods
Effects and animations
AJAX
Utilities
Short selector example
Document.getElementsByClassName(‘classname’)
$(‘.classname’) //jQuery
Document.getElementsById(‘idname’)
$(‘#idname’) //jquery
Document.getElementsByTagName(‘tagname’)
$(‘tagname’)
jQuery start code
$(document).ready(function(){
})
Let a =
document.getElementByQuerySelector(‘#idname’).innerHtml();
Let a = $(‘#idname’).html(); // jQuery code
jQuery Selector
$(“.class”)
$(“#id”)
$(“tagname”)
$(“*”)
$(“ul li”)
$(“.a , .b”)
$(“h1, p, div”)
$(“p:first”)
$(“p:last”)
$(“li:even”)
$(“li:odd”)
$(“.container”).css(“property” , “value”)
$(“p”).css(“border” , “2px solid”)
jQuery Event Methods
Click
Dblclick
Mouseenter
mouseleave
click
<script>
$(document).ready(function(){
$(".box1").click(function(){
$(".box1").css("background-color" , "blue")
})
});
</script>
2nd event
$(".box1").click(function(){
var a= $(".box1").html();
console.log(a)
})
dblclick
$(".box1").dblclick(function(){
$(".box1").css("background-color" , "red")
})
Mouseenter
$(".box1").mouseenter(function(){
$(".box1").css("background-color" , "red")
OR
Alert(“you entered mouse”)
})
mouseleave
$(".box1").mouseleave(function(){
$(".box1").css("background-color" , "yellow")
})
Hide()
$(".box1").click(function(){
$(this).hide();
})
Hover:
$(“.box1").hover(function(){
alert("You entered p1!");
},
function(){
alert("Bye! You now leave p1!");
});
Html form field
Focus:
$("#fname ").focus(function(){
$(this).css("background-color" , "pink")
})
Blur:
$("#fname , #depart, #city").blur(function(){
$(this).css("background-color" , "")
})
Change
$(" #city").change(function(){
$(this).css("background-color" , “yellow")
})
$(" #city").change(function(){
var a= $(this).val();
$("#demo").html(a)
})
select
$(“#fname , #deprt”).select(function(){
$(this).css(“background-color”, “yellow”)
$(“#fname , #deprt”).submit(function(){
Alert(“your form is submitted successfully”)