Thursday, October 22, 2020

Jquery Hide,Show,Toggel Effects




  jQuery hide() Method

  The jQuery  if you want to hide the any content or any think then use method

  Syntax:

        $(selector).hide();  

        $(selector).hide(speed, callback);  

        $(selector).hide(speed, easing, callback);  


  speed: It is an optional parameter. It specifies the speed of the delay. Its possible vales are slow,                fast and milliseconds.

  easing: It specifies the easing function to be used for transition.

  callback: It is also an optional parameter. It specifies the function to be called after completion of                   hide() effect.


  <!DOCTYPE html>

  <html>

  <head>

   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">             </script>

   <script>

    $(document).ready(function(){

    $("p").click(function(){

    $(this).hide();

      });

   });

 </script>

 </head>

 <body>

 <p>If you click on me, I will disappear.</p>

 <p>Click me away!</p>

 <p>Click me too!</p>

</body>

</html>

Jquery hide effects with speed 


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example of jQuery Animated Show Hide Effects</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<style>
    p{
        padding: 15px;
        background: #F0E68C;
    }
</style>
<script>
$(document).ready(function(){
    // Hide displayed paragraphs with different speeds
    $(".hide-btn").click(function(){
        $("p.normal").hide();
        $("p.fast").hide("fast");
        $("p.slow").hide("slow");
        $("p.very-fast").hide(50);
        $("p.very-slow").hide(2000);
    });
});
</script>
</head>
<body>
    <button type="button" class="hide-btn">Hide Paragraphs</button> 
    <p class="very-fast">This paragraph will show/hide with very fast speed.</p>
    <p class="normal">This paragraph will show/hide with default speed.</p>
    <p class="fast">This paragraph will show/hide with fast speed.</p>
    <p class="slow">This paragraph will show/hide with slow speed.</p>
    <p class="very-slow">This paragraph will show/hide with very slow speed.</p>
</body>
</html>

  jQuery show() Method


    The jQuery show() method is used to show the selected elements.
    
      Syntax:

        $(selector).show();  

        $(selector).show(speed, callback);  

        $(selector).show(speed, easing, callback);  


    Example

    <!DOCTYPE html>
   <html>
   <head>
    <script                                                    src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script>
     $(document).ready(function(){
      $("#show").click(function(){
      $("p").show();
          });
      });
   </script>
   </head>
   <body>
     <p>If you click on the "Hide" button, I will disappear.</p>
  <button id="show">Show</button>
  </body>
  </html>


 Jquery hide effects with speed Example 

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example of jQuery Animated Show Hide Effects</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<style>
    p{
        padding: 15px;
        background: #F0E68C;
    }
</style>
<script>
$(document).ready(function(){  
    // Show hidden paragraphs with different speeds
    $(".show-btn").click(function(){
        $("p.normal").show();
        $("p.fast").show("fast");
        $("p.slow").show("slow");
        $("p.very-fast").show(50);
        $("p.very-slow").show(2000);
    });
});
</script>
</head>
<body>
    <button type="button" class="show-btn">Show Paragraphs</button>
    <p class="very-fast">This paragraph will show/hide with very fast speed.</p>
    <p class="normal">This paragraph will show/hide with default speed.</p>
    <p class="fast">This paragraph will show/hide with fast speed.</p>
    <p class="slow">This paragraph will show/hide with slow speed.</p>
    <p class="very-slow">This paragraph will show/hide with very slow speed.</p>
</body>
</html>

 jQuery Toggle() Method

    You can also toggle between hiding and showing an element with                                 the toggel() method.


    Syntax

        $(selector).toggle(speed,callback);


  Example:-

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>Example of jQuery Toggle Effect</title>
     <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
     <style>
       p{
           padding: 15px;
           background: #F0E68C;
        }
     </style>
     <script>
      $(document).ready(function(){
        // Toggles paragraphs display
        $(".toggle-btn").click(function(){
          $("p").toggle();
       });
    });
    </script>
    </head>
     <body>
      <button type="button" class="toggle-btn">Toggle Paragraphs</button> 
      <p>This is a paragraph.</p>
      <p>This is another paragraph.</p>
     </body>
  </html> 


Jquery hide effects with speed Example                            
    <script>
$(document).ready(function(){ // Toggles paragraphs with different speeds $(".toggle-btn").click(function(){ $("p.normal").toggle(); $("p.fast").toggle("fast"); $("p.slow").toggle("slow"); $("p.very-fast").toggle(50); $("p.very-slow").toggle(2000); }); }); </script>



You can also see the example of callback function in jquery toggel() method


Example-

<script> $(document).ready(function(){ // Display alert message after toggling paragraphs $(".toggle-btn").click(function(){ $("p").toggle(1000, function(){ // Code to be executed alert("The toggle effect is completed."); }); }); }); </script>




 

Jquery Effects



"Query effects can be categorized into fading, sliding, hiding/showing and animation effects."

 


 A complete list of jQuery effect methods are given below:

No.MethodDescription
1)animate()performs animation.
2clearQueue()It is used to remove all remaining queued functions from the selected elements.
3)delay()sets delay execution for all the queued functions on the selected elements.
4dequeue()It is used to remove the next function from the queue, and then execute the function.
5)fadein()shows the matched elements by fading it to opaque. In other words, it fades in the selected elements.
6)fadeout()shows the matched elements by fading it to transparent. In other words, it fades out the selected elements.
7)fadeto()adjusts opacity for the matched element. In other words, it fades in/out the selected elements.
8)fadetoggle()shows or hides the matched element. In other words, toggles between the fadeIn() and fadeOut() methods.
9)finish()It stops, removes and complete all queued animation for the selected elements.
10)hide()hides the matched or selected elements.
11)queue()shows or manipulates the queue of methods i.e. to be executed on the selected elements.
12)show()displays or shows the selected elements.
13)slidedown()shows the matched elements with slide.
14)slidetoggle()shows or hides the matched elements with slide. In other words, it is used to toggle between the slideUp() and slideDown() methods.
15)slideup()hides the matched elements with slide.
16)stop()stops the animation which is running on the matched elements.
17)toggle()shows or hides the matched elements. In other words, it toggles between the hide() and show() methods.

Tuesday, October 6, 2020

JQuery Selectors




Today we will discuss the JQuery Selectors 

jQuery selectors are one of the most important parts of the jQuery library.


JQuery Selecters

jQuery selectors are used to find HTML elements based on their name, id, classes, types, attributes, values of attributes and much more. The selectors based on css selecters .

  • All selectors in jQuery start with the dollar sign and parentheses: $().
  • In other terms you are adding the TAG Name ,TAG ID ,TAG,Class
    
Syntax:-

        $(selector expression, context)
            
        jQuery(selector expression, context)

Example:-

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").hide();
  });
});
</script>
</head>
<body>

<h2>This is a heading</h2>

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

<button>Click me to hide paragraphs</button>

</body>
</html>

How To Use The Selectors

S.No.SelectorDescription
1)Name:It selects all elements that match with the given element name.
2)#ID:It selects a single element that matches with the given id.
3).Class:It selects all elements that matches with the given class.
4)Universal(*)It selects all elements available in a DOM.
5)Multiple Elements x,y,zIt selects the combined results of all the specified selectors x,y and z.

Some Other JQuery Selectors

SelectorExampleDescription
*$("*")It is used to select all elements.
#id$("#firstname")It will select the element with id="firstname"
.class$(".primary")It will select all elements with class="primary"
class,.class$(".primary,.secondary")It will select all elements with the class "primary" or "secondary"
element$("p")It will select all p elements.
el1,el2,el3$("h1,div,p")It will select all h1, div, and p elements.
:first$("p:first")This will select the first p element
:last$("p:last")This will select he last p element
:even$("tr:even")This will select all even tr elements
:odd$("tr:odd")This will select all odd tr elements
:first-child$("p:first-child")It will select all p elements that are the first child of their parent
:first-of-type$("p:first-of-type")It will select all p elements that are the first p element of their parent
:last-child$("p:last-child")It will select all p elements that are the last child of their parent
:last-of-type$("p:last-of-type")It will select all p elements that are the last p element of their parent
:nth-child(n)$("p:nth-child(2)")This will select all p elements that are the 2nd child of their parent
:nth-last-child(n)$("p:nth-last-child(2)")This will select all p elements that are the 2nd child of their parent, counting from the last child
:nth-of-type(n)$("p:nth-of-type(2)")It will select all p elements that are the 2nd p element of their parent
:nth-last-of-type(n)$("p:nth-last-of-type(2)")This will select all p elements that are the 2nd p element of their parent, counting from the last child
:only-child$("p:only-child")It will select all p elements that are the only child of their parent
:only-of-type$("p:only-of-type")It will select all p elements that are the only child, of its type, of their parent
parent > child$("div > p")It will select all p elements that are a direct child of a div element
parent descendant$("div p")It will select all p elements that are descendants of a div element
element + next$("div + p")It selects the p element that are next to each div elements
element ~ siblings$("div ~ p")It selects all p elements that are siblings of a div element
:eq(index)$("ul li:eq(3)")It will select the fourth element in a list (index starts at 0)
:gt(no)$("ul li:gt(3)")Select the list elements with an index greater than 3
:lt(no)$("ul li:lt(3)")Select the list elements with an index less than 3
:not(selector)$("input:not(:empty)")Select all input elements that are not empty
:header$(":header")Select all header elements h1, h2 ...
:animated$(":animated")Select all animated elements
:focus$(":focus")Select the element that currently has focus
:contains(text)$(":contains('Hello')")Select all elements which contains the text "Hello"
:has(selector)$("div:has(p)")Select all div elements that have a p element
:empty$(":empty")Select all elements that are empty
:parent$(":parent")Select all elements that are a parent of another element
:hidden$("p:hidden")Select all hidden p elements
:visible$("table:visible")Select all visible tables
:root$(":root")It will select the document's root element
:lang(language)$("p:lang(de)")Select all p elements with a lang attribute value starting with "de"
[attribute]$("[href]")Select all elements with a href attribute
[attribute=value]$("[href='default.htm']")Select all elements with a href attribute value equal to "default.htm"
[attribute!=value]$("[href!='default.htm']")It will select all elements with a href attribute value not equal to "default.htm"
[attribute$=value]$("[href$='.jpg']")It will select all elements with a href attribute value ending with ".jpg"
[attribute|=value]$("[title|='Tomorrow']")Select all elements with a title attribute value equal to 'Tomorrow', or starting with 'Tomorrow' followed by a hyphen
[attribute^=value]$("[title^='Tom']")Select all elements with a title attribute value starting with "Tom"
[attribute~=value]$("[title~='hello']")Select all elements with a title attribute value containing the specific word "hello"
[attribute*=value]$("[title*='hello']")Select all elements with a title attribute value containing the word "hello"
:input$(":input")It will select all input elements
:text$(":text")It will select all input elements with type="text"
:password$(":password")It will select all input elements with type="password"
:radio$(":radio")It will select all input elements with type="radio"
:checkbox$(":checkbox")Itwill select all input elements with type="checkbox"
:submit$(":submit")It will select all input elements with type="submit"
:reset$(":reset")It will select all input elements with type="reset"
:button$(":button")It will select all input elements with type="button"
:image$(":image")It will select all input elements with type="image"
:file$(":file")It will select all input elements with type="file"
:enabled$(":enabled")Select all enabled input elements
:disabled$(":disabled")It will select all disabled input elements
:selected$(":selected")It will select all selected input elements
:checked$(":checked")It will select all checked input elements

 

Next -JQuery Effects




Jquery Hide,Show,Toggel Effects

  jQuery hide() Method   The jQuery  if you want to hide the any content or any think then use method   Syntax :           $(selector).hide(...