Here I am discussing the top ten functions of jQuery.
- hide() function
- show() function
- toggle() function
- slideUp() function
- slideDown() function
- slideToggle() function
- fadeOut() function
- fadeIn() function
- fadeToggle()
- animate() function
Now I'll explain the topic.
- Hide function
It is used to hide the selected html element in a simple way. As a name it only works in hidden selected element. In jQuery the Hide () method is very useful. By using this method you can hide HTML elements with the hide().
- <script>
-
- $(‘#hide_jQuery’).click(function(){
- $(‘# jQuery’).hide();
- });
- $(‘#show_ jQuery’).click(function(){
- $(‘# jQuery’).show();
- });
-
- </script>
- <div id=”hide_ jQuery”></div>
- <div id=”show_ jQuery”></div>
- <div id=” jQuery”></div>
This example, we have created a hide function to hide the selected element. I have created three div tags for this purpose.
Below is the First one, the div tag where we have to click for hiding the jQuery.
- <div id=”hide_ jQuery”></div>
- Show function
It is used to show the selected html element. We can say that these functions work in the opposite in hide function. But before calling this function it must use the hide function on the same element
Example
- <script>
-
- $(‘#hide_ jQuery’).click(function(){
- $(‘# jQuery’).hide();
- });
- $(‘#show_ jQuery’).click(function(){
- $(‘# jQuery’).show();
- });
- </script>
- <div id=”hide_ jQuery”></div>
- <div id=”show_ jQuery”></div>
- <div id=” jQuery”></div>
- Toggle function
It is used to both (hide, show) functions to toggle between for the click event for the selected elements. It means this function is used to hide or show the specific selected element. A toggle functions well compared to hide and show function.
Example
- <!doctype html>
- <html lang="en">
-
- <head>
- <meta charset="utf-8">
- <title>toggle demo</title>
- <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
- </head>
-
- <body>
- <button>Toggle</button>
- <div>Hello</div>
- <script>
- $("button").click(function()
- {
- $("div").toggle();
- });
- </script>
- </body>
-
- </html>
For more details click on link.
- SlideUp function
This function is used to slide and show element's up side. It slides the selected elements up and removes it slowly.
Example
- <script type="text/javascript">
- $(document).ready(function ()
- {
- $("#btnSlideUp").click(function ()
- {
- $("#login_wrapper").slideUp();
- return false;
- });
- });
- </script>
For more details click on link.
- SlideDown function
This function is used to slide and hide an element on down side.
Example
- <script type="text/javascript">
- $(document).ready(function ()
- {
- $("#btnSlideDown").click(function ()
- {
- $("#login_wrapper").slideDown();
- return false;
- });
- });
- </script>
For more details click on link.
- SlideToggle function
This method is between slideUp() method and slideDown() method. It shows/hides an element in up/down side.
Example
- <script type="text/javascript">
- $(document).ready(function ()
- { $("#btnSlideToggle").click(function ()
- {
- $("#login_wrapper").slideToggle();
- return false;
- });
- });
- </script>
For more details click on link.
- FadeOut Function
The jQuery fadeOut() method fades out a visible element and hides it.
Syntax
$(selector).fadeOut(speed,callback);
Example
- <script type="text/javascript">
- $(document).ready(function ()
- {
- $("#btnEffect").click(function ()
- {
- $("#panelPersonalInfo").fadeOut();
- $("#panelAddressInfo").fadeOut("slow");
- $("#panelLoginInfo").fadeOut(4000); //millisecond
- return false;
- });
- });
- </script>
For more details click on link.
- FadeIn function
The jQuery fadeIn() method displays a hidden element by fading it in.
The syntax is
$(selector).fadeIn(speed,callback);
Example
- <script type="text/javascript">
- $(document).ready(function ()
- {
- $("#btnEffect").click(function ()
- {
- $("#panelPersonalInfo").fadeIn();
- $("#panelAddressInfo").fadeIn("slow");
- $("#panelLoginInfo").fadeIn(4000); //millisecond
- return false;
- });
- });
- </script>
For more details click on link.
- FadeToggle
The jQuery fadeToggle() method toggles between the fadeIn() and fadeOut() methods. If the page's elements are faded out then fadeToggle() will fade them in and if the elements are faded in then fadeToggle() will fade them out.
Example
- <script type="text/javascript">
- $(document).ready(function ()
- {
- $("#btnEffect").click(function ()
- {
- $("#panelPersonalInfo").fadeToggle();
- $("#panelAddressInfo").fadeToggle("slow");
- $("#panelLoginInfo").fadeToggle(4000); //millisecond
- return false;
- });
- });
- </script>
For more details click on link.
- Animate function
In jQuery the animate() method is very useful. By using this method we can change the size of elements. In this example we create a div element which contains an Image; when we move the mouse over the image, the image size will change. First of all you add an image to the application. Add a new form to the application and add the following HTML code to the aspx page.
Example
- <div style="height: 100px; width: 100px; position: relative">
- <img src="animate.gif" id="img" />
- </div>
Now add the following code in the head section.
- <script type="text/javascript">
- $(document).ready(function () {
-
- $("div").mouseover(function ()//mouseover function will execute when mouse pointer will reach on <div>element
- {
- $("img").animate({ height: 300 }, "slow"); //image height will change by using animate method
- $("img").animate({ width: 300 }, "slow");
- $("img").animate({ height: 100 }, "slow");
- $("img").animate({ width: 100 }, "slow");
- });
- }
- );
- </script>
In the above code we create a mouseover function.
- $("img").animate({ height: 300 }, "slow"); //image height will change by using animate method
- $("img").animate({ width: 300 }, "slow");
- $("img").animate({ height: 100 }, "slow");
- $("img").animate({ width: 100 }, "slow");
For more details click on link.