jQuery Selector How to - Select div inside ul li








Question

We would like to know how to select div inside ul li.

Answer


<!--   ww  w .  java  2  s. co m-->
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.4.4.min.js'></script>
<script type='text/javascript'>
$(window).load(function(){
    $('ul li div').click(function() {
        $(this).css({ 'border' : '1px solid green' });
    });
});
</script>
</head>
<body>
  <ul>
    <li><img src='http://www.java2s.com/style/download.png'>
      <div>Test content in the first list item</div>
    </li>
  </ul>
</body>
</html>

The code above is rendered as follows: