jQuery Method How to - Use add() to add tag








Question

We would like to know how to use add() to add tag.

Answer


 <!--  w w  w .  ja v a  2 s  .c  om-->
<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
        $(document).ready(function(){
           $("p").add(document.getElementById("a")).css("background", "yellow");
        });
    </script>
  </head>
  <body>
          <p>Hello</p>
          <p id="a">Hello</p>
  </body>
</html>

The code above is rendered as follows: