Get selected elements by index

Description

The following code shows how to select LI list element by index.

Example


<!DOCTYPE html>
<html>
<head>
<script
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
  <!--   w  w  w . j av a  2s  .  c  o  m-->
</script>
<script>
  $(function() {
    var listElements = $("li");
    var secondEl = listElements.get(2);
    var fourthEl = listElements.get(3);
    document.writeln(secondEl.innerHTML + " and " + fourthEl.innerHTML);
  });
</script>
</head>
<body>
  <ul>
    <li>A</li>
    <li>B</li>
    <li>C</li>
    <li>D</li>
    <li>E</li>
    <li>F</li>
  </ul>
</body>
</html>

Click to view the demo





















Home »
  jQuery »
    jQuery Example »




Animation
DOM
Event
Form
List
Select
Style
Table
Utilities