JavaScript DHTML/jQuery/wrap

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

Wrap a new b around all of the 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").wrap("");
               
        
       });
   </script>
   
 </head>
 <body>
   <body>
        asdf

asdf:

   </body>

</html>


 </source>
   
  


Wrap another tag

   <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").wrap("
asdf
");
       });
   </script>
 </head>
 <body>
   <body>

a

b
 </body>

</html>



 </source>
   
  


wrap(elem): Wrap each matched element with the specified element.

   <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").wrap(document.createElement("b"));
               
        
       });
   </script>
   
 </head>
 <body>
   <body>
        asdf

asdf:

   </body>

</html>


 </source>
   
  


wrap(html): injecting additional structure into a document

   <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").wrap("");
               
        
       });
   </script>
   
 </head>
 <body>
   <body>
        asdf

asdf:

   </body>

</html>


 </source>
   
  


Wrap p with div tag

   <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").wrap("
");
 }

);

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

h4, p {

   margin: 5px;  

} div {

   background: #fedd58;
   border: 1px solid #ebcb49;
   margin: 3px;

}

   </style>
 </head>
 <body>

asdf

 </body>

</html>

 </source>
   
  


Wrap to create and add a border

   <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").wrap("
");
       });
   </script>
 <style>
     div { border: 2px solid blue; }
 </style>
   
 </head>
 <body>
   <body>

Hello

 </body>

</html>



 </source>