jQuery Method How to - Use add(expr): adds more elements








Question

We would like to know how to use add(expr): adds more elements.

Answer


 <!--from   ww  w .j  a v  a2s  .  c  o  m-->
<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("div").add("p").css("background", "yellow");
        });
    </script>
  </head>
  <body>
          <div>asdf</div>
          <div>asdf</div>
          <div>asdf</div>
          <div>asdf</div>
  </body>
</html>

The code above is rendered as follows: