JQuery Select Empty Child Element

From CoderLearner
Jump to: navigation, search

Description

$(':empty') is the empty selector to select element that it is empty.

Example 1

<!DOCTYPE html>
<html>
   <head>
      <title>Contain</title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <script 
         type="text/javascript" 
         src="/lib/jquery-1.7.2.min.js">				 
      </script>
      <script>
         $(document).ready(function() {
            $(':empty').css('background-color','blue');
         });
      </script>
   </head>
   <body>
      <table>
         <tr>
            <td>Name</td>
            <td></td> <!-- empty -->
            <td>Salary</td>
         </tr>
         <tr>
            <td>Bob</td>
            <td>Houston,Tx</td>
            <td>382k</td>
         </tr>
         <tr>
            <td>Jing</td>
            <td>Thailand</td>
            <td></td><!-- empty -->
         </tr>
         <tr>
            <td></td><!-- empty -->
            <td>Canada</td>
            <td></td><!-- empty -->
         </tr>
      </table>
   </body>
</html>

Try It

<seo metagenerator="jquery tutorial" title="Jquery/Ajax" metakeywords="jquery greater,jquery gt, jquery lt, less then, odd jquery,jquery find element, even jquery,jquery event, jquery mouse click, jquery double click, jquery hover, jquery string, jquery array, jquery button, jquery attriubtes" metadescription="jquery button, jquery attriubte, jquery example, jquery tutorial, jquery sample"/>