To assign a click event to all paragraphs we use this method. this is the syntax:
$("p").click();
now, in next step when an event fires, You must pass a function to this event:
$("p").click(function(){
});
$(document).ready()
The $(document).ready() method executes a function when the document is fully loaded.
click()
The function gets executed when the user clicks on the HTML element.
Example
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
});
});
</script>
</head>
<body>
<p>If you will click it will disappear. </p>
<p>Click me too!</p>
<p>and now!</p>
</body>
</html>
0 Comment(s)