<script>
$(document).ready(function(){
$("button").click(function(){
$("#p1").css("color", "red").slideUp(2000).slideDown(2000);
});
});
</script>
onload() | document.ready() |
---|---|
We can have only one onload() function in a page. | We can have more than one document.ready() function. |
This function is called when DOM and images are loaded on the page. | This function is called when DOM is loaded. |
It is a standard event in the DOM. | This event is specific to jQuery. |
Syntax: <body onload="javascript function name or the actual script"> | Syntax: <script type="text/javascript"> $(document).ready(function() { //Script goes here }); </script> |
jQuery | JavaScript |
---|---|
jQuery is a framework. | JavaScript is a language. |
jQuery is a fast and concise JavaScript library that simplifies HTML document. | JavaScript is most popular scripting language on Internet which works on all major browsers. |
jQuery has Document Object Model (DOM). | JavaScript is a combination of ECMA script and DOM. |
Example: jQuery ID Selector var $val = $("#hello"); | Example: JavaScript ID Selector var $val = document.querySelector('#hello'); |
Example: jQuery Class Selector var $val = $('.welcome'); $ ('body') .css ('background', '#ccc'); | Example: JavaScript Class Selector var $val = document.querySelector('.welcome'); Function changeBackground(color){ Document.body.style.background = color;} onload="changeBackground('red');" |
Hover | Mouseover |
---|---|
Hover specifies two functions to run when the mouse pointer hovers over the selected elements. | Mouseover occurs when the mouse pointer is over the selected element. |
The hover() method triggers both the mouseenter and mouseleave events. | The mouseover() method triggers the mouseover event or attaches a function to run when a mouseover event occurs. |
Syntax: $(selector).hover(inFunction,outFunction) Parameters, inFunction: It specifies the function to run when the mouseenter event occurs . OutFunction: It specifies the function to run when the mouseleave event occurs. | Syntax: Trigger the mouseover event for the selected elements: $(selector).mouseover() Attach a function to the mouseover event: $(selector).mouseover(function) Parameters, function: It specifies the function to run when the mouseover event is triggered. |