JavaScript Tutorial/jQuery/contents

Материал из Web эксперт
Версия от 11:25, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

contents() finds all the child nodes inside the matched elements

   <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").contents().not("[nodeType=1]").wrap("<b/>");
                   
       });
   </script>
 </head>
 <body>
   <body>

Hello <a href="http://wbex.ru/">wbex</a>asdf

   </body>

</html></source>


Get tag content

   <source lang="javascript">

<html>

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

Hello spandata

 </body>

</html></source>


Wrap tag to another tag

   <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").contents().filter(function(){ return this.nodeType != 1; }).wrap("<b/>");
       });
   </script>
 </head>
 <body>
   <body>

Hello spandata

 </body>

</html></source>