JavaScript Tutorial/jQuery/after

Материал из Web эксперт
Перейти к: навигация, поиск

Add after

   <source lang="javascript">

<html>

 <head>
   <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
   <script type="text/javascript">
       $(document).ready(function(){
              $("p").after("Hello");


       });
   </script>
 </head>
 <body>
   <body>

a

b
 </body>

</html></source>


Add after text node

   <source lang="javascript">

<html>

 <head>
   <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
   <script type="text/javascript">
       $(document).ready(function(){
           $("p").after( document.createTextNode("Hello") );
  
       });
   </script>
 </head>
 <body>
   <body>
        b

p

 </body>

</html></source>


Add after text node created from document.createTextNode

   <source lang="javascript">

<html>

 <head>
   <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
   <script type="text/javascript">
       $(document).ready(function(){
             $("p").after( document.createTextNode("Hello") );
       });
   </script>
 </head>
 <body>
   <body>

a

b
 </body>

</html></source>


Add before and after

   <source lang="javascript">

<html>

 <head>
   <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
   <script type="text/javascript">

$(document).ready(

 function() {
   $("p")
     .before(
"

Quotes

"
     )
     .after(
"

\n" + " - after\n" + "

\n"
     );
 }

);

   </script>
   <style type="text/css">

p {

   margin: 5px;

} p.tmpAttribution {

   text-align: right;

}

   </style>
 </head>
 <body>

asdf

 </body>

</html></source>


Inserts a jQuery object (similar to an Array of DOM Elements) after all paragraphs.

   <source lang="javascript">

<html>

 <head>
   <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
   <script type="text/javascript">
       $(document).ready(function(){
         $("p").after( $("b") );
               
        
       });
   </script>
   
 </head>
 <body>
   <body>
        asdf

asdf:

   </body>

</html></source>


Use after to switch node

   <source lang="javascript">

<html>

 <head>
   <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
   <script type="text/javascript">
       $(document).ready(function(){
           $("p").after( $("b") );
  
       });
   </script>
 </head>
 <body>
   <body>
        b

p

 </body>

</html></source>