jquery chaining

chaining allows us to execute multiple jquery methods(on the same element) within a single statement.

jquery method chaining

jquery heavily relies on chaining.this makes it easy to call several methods on the same selection.

a method chain is also known as a train wreck due to an increasing amount of methods stacked one after another in one line.

it also makes code more clear and prevents executing the same selection several times (hence improving performance).

it improves readability and reduces the amount of source code.

example :following example chains together the slidedown(), addclass() and css() methods in one line.

<head>
            
                  <title> chaining the methods </title>
           
<script src='//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js' >
           
                $('#person).slidedown('slow').addclass('group').css('margin-left','11px');
           
           
              </script>
           
           </head>

you can formats your above chaining example codes.

<head>
           
               <title> chaining the methods </title>
           
           
               <script src='//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js' >
           
           
                 $('#person).slidedown('slow')
           
               .addclass('group')
           
           
              .css('margin-left','11px');
           
           
            </script>
           
           
            </head>