jQuery Events
Event is the visitor's activity performed on the web page. This is used to make the web page dynamic and interactive. You have also noticed these events while the web surfing, like - event occurs on mouse click, on form submission, by pressing a key on the keyboard.
List of some jQuery events
Events | Description |
onblur | It occurs when the element loses focus. |
onchange | It occurs when the value of an element has changed. |
onfocus | It occurs when an element gets focus. |
onselect | It occurs when some text is selected. |
onsubmit | It occurs when a form is submitted. |
onclick | It occurs when an element is clicked. |
ondblclick | It occurs when an element is double-clicked. |
onmousedown | It occurs when the mouse is over the element and left mouse button is pressed down. |
onmouseenter | It occurs when the mouse pointer enters the selected element. |
onmouseleave | It occurs when the mouse pointer leaves the selected element. |
onmousemove | It occurs when the mouse moves inside the selected element. |
onmouseout | It occurs when the mouse pointer leaves the selected element. |
onkeypress | It occurs when the user presses a key on the keyboard. |
onkeyup | It occurs when a keyboard key is released. |
onerror | It occurs when an error occurs while loading a document. |
onresize | It occurs when the browser window's size is changed. |
onscroll | It occurs when the element is scrolled. |
onload | It occurs when the element has been loaded. |
Example of jQuery events
<style>
.sliderDiv {
width: 300px;
height: 100px;
padding: 20px;
background-color: pink;
font-size: 25px;
}
</style>
<div id="slider" class="sliderDiv">Some content goes here</div>
<button id="slidediv">Click Here</button>
<script>
(function( $ ) {
$("button#slidediv").click(function(){
$("div#slider").slideToggle('slow');
});
})(jQuery);
</script>
Output of the above code
In the above example, when the user click on the button of id 'slidediv', the div box is slided up or down.
Further, we have explained the most common events in brief.