JavaScript DHTML/jQuery/before

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

Add before and after

   <source lang="html4strict">

<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>
   
  


Add tag before

   <source lang="html4strict">
  

<html>

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


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

p

 </body>

</html>


 </source>
   
  


Add text node before

   <source lang="html4strict">
  

<html>

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

p

 </body>

</html>


 </source>
   
  


before(content): Insert content before each of the matched elements.

   <source lang="html4strict">
 

<html>

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

asdf:

   </body>

</html>


 </source>
   
  


Inserts a DOM element before all paragraphs.

   <source lang="html4strict">
 

<html>

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

asdf:

   </body>

</html>


 </source>
   
  


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

   <source lang="html4strict">
 

<html>

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

asdf:

   </body>

</html>


 </source>
   
  


Inserts some HTML before all paragraphs.

   <source lang="html4strict">
 

<html>

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

asdf:

   </body>

</html>


 </source>