Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Use of Delegate() Method in jQuery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 380
    Comment on it

    The delegate method can be used in two ways:-

    1. If we have a parent element, and we want to attach an event to each one of its child elements, this delegate() method is used.

    Ex: Un-ordered List Instead of attaching an event to each

  • element, we can attach a single event to
      element.

      Example:

      <script type="text/javascript">
          $(function (){
              $("ul").delegate("li", "click", function(){
                  $(this).hide();
              });
          });
      </script>
      
      1. When an element is not available on the current page, this method is used. .live() method is also used for the same purpose but, delegate() method is a bit faster.

      Example:

      <script type="text/javascript">
          $(function (){
              $("ul").delegate("li", "click", function(){
                  $(this).hide();
              });
          });
      </script>
      
Comment on it

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: