Event Handling Functions using jQuery

Event handling are the important function in jQuery. Event handlers are called when something happens eg: clicking a button. It is referred as trigger of an event.

Let us describe with simple example:

<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 $("button").click(function(){
 $("p").hide();
 });
});
</script>
</head>
<body>
<h2>Learnwebdevelopment.info</h2>
<p>Hai</p>
<p>Welcome</p>
<button>Click me to hide</button>
</body>
</html>

EXPLANATION:

By clicking (triggering) a button i.e; $(“button”).clicking (function(){*** some statements***}) it will hide the all details inside the paragraph i.e;  $(“p”).hide();

Some jQuery Event Functions:

$(document).ready(function) -Triggers the function on ready event of the document

$( selector).click(function) –  Triggers the function on click

$(selector).dblclick(function) – Triggers the function on double click

$(selector).hide(function) – Triggers the function to hide the selected items

$(selector).toggle(function) – Triggers the function on toggle

Posted in jQuery Tagged with: