JavaScript DHTML/jQuery/find

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

Change the font weight and color of all Italic text

   <source lang="html4strict">
  

<html>

 <head>
   <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
   <style type="text/css">
       a.test { font-weight: bold; color:red;}
   </style>
   <script type="text/javascript">
$(document).ready(function(){
   $("input.buttonA").click(function(){ $("div.contentToChange").find("em").css({color:"#993300", fontWeight:"bold"}); });
});
   </script>
 </head>
 <body>
   <input type="button" value="Change" class="buttonA" />

Header 2

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.

 </body>

</html>


 </source>
   
  


Find all children with a class "selected" of each div.

   <source lang="html4strict">


<html>

 <head>
   <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
   <script type="text/javascript">
       $(document).ready(function(){
               
              $("div").children(".selected").css("color", "blue");
                   
       });
   </script>
 </head>
 <body>
   <body>
And Again
             asdf
   </body>

</html>

 </source>
   
  


find(expr): searching is done using a jQuery expression

   <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").find("span").css("color","red");
                   
       });
   </script>
 </head>
 <body>
   <body>
       

bad or good.

   </body>

</html>

 </source>
   
  


Find tag in 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").find("span").css("color","red");
       });
   </script>
 </head>
 <body>
   <body>

Hello

 </body>

</html>



 </source>