jQuery Selector How to - Select specific ordered lists before certain index








Question

We would like to know how to select specific ordered lists before certain index.

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(){<!--   www  .ja v a 2 s  . c o  m-->
    $('#wikiInfo').find("ol:lt(2)").css({"color":"red","border":"2px solid red"});
});
</script>
</head>
<body>
  <div id="wikiInfo">
    <ol>
      <li>1</li>
    </ol>
    <p></p>
    <ol>
      <li>2</li>
    </ol>
    <p></p>
    <ol>
      <li>3</li>
    </ol>
  </div>
</body>
</html>

The code above is rendered as follows: