Menu Search Sign up

Call JQuery Method to Achieve HTML Effect

Not only can you put your own custom JavaScript code into a JQuery event, in your JavaScript code segment, you can also call a JQuery method to achieve your desired HTML effects like Hide, Show, Toggle, Slide, Fade, and Animate.

Let's look at the following example:

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").hide(1000);
  });
});
</script>
</head>
<body>
<button>Hide</button>
<p>This is a paragraph with little content.</p>
<p>This is another small paragraph.</p>
</body>
</html>

In the above example, when a user clicks the button, a JQuery event "click" is fired. This will invoke your custom code inside the $("button").click JQuery event. And the custom code just hides the text enclosed by the <p> tag.