jQuery Method How to - Use after() to switch node








Question

We would like to know how to use after() to switch node.

Answer


 <!-- w w w .j av a2 s . co 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(){
            $("p").after( $("b") );
        });
    </script>
  </head>
  <body>
         <b>b</b>
         <p>p</p>
  </body>
</html>

The code above is rendered as follows: