JQuery Selector Descendant

From CoderLearner
Jump to: navigation, search

Description

A descendant can be a child, a grandchild, great-grand-child, and so on and on of the ancestor element.

Syntax

$("ancestor descendant")

Example 1

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Select</title>
      <script 
         type="text/javascript" 
         src="/lib/jquery-1.7.2.min.js">				 
      </script>
      <style>
         .mark {
            background-color:green;
         }
      </style>
      <script>
         $().ready(function() {
            $('div ul').css({'border':'1px solid green','width':'58px'});
            $('span span').addClass('mark');
         });
      </script>
   </head>
   <body> 
      <div id="top2">
         <ul>
            <li>11</li>
            <li>21</li>
            <li>20</li>
            <li>21</li>
            <li>20</li>
         </ul>
      </div>
      <span>
         <span>
            Good
         </span>
         <a href="#">Photo</a>
      </span>
   </body>
</html>

Try It