JQuery Selector Child

From CoderLearner
Jump to: navigation, search

Description

Select all elements that is the child of a parent element.

Syntax

$("parent > child")

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 {
            list-style-type: none;
            border:1px solid #999900;
            width:130px;
         }
      </style>
      <script>
         $().ready(function() {
            $('div#top1 > ul').addClass('mark');
         });
      </script>
   </head>
   <body> 
      <div id="top1">
         <ul>
            <li>One</li>
            <li>Two</li>
            <li>Three</li>
         </ul>
         <div  id="top2">
            <ul>
               <li>1</li>
               <li>2</li>
            </ul>
         </div>
      </div>
   </body>
</html>

Try It