jQuery HTML Element How to - Hide the rest of the list








Question

We would like to know how to hide the rest of the list.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from  w  w  w .j  a  v a 2s  .c  om-->
    $('li:gt(3)').hide();
});
</script>
</head>
<body>
  <ul>
    <li>list</li>
    <li>list</li>
    <li>list</li>
    <li>list</li>
    <li>hide this list</li>
    <li>hide this list</li>
    <li>hide this list</li>
    <li>hide this list</li>
    <li>hide this list</li>
    <li>hide this list</li>
  </ul>
</body>
</html>

The code above is rendered as follows: