Select last from selected

Description

The following code shows how to select last from selected.

Example


<!DOCTYPE html>
<html>
<head>
<script
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
  <!--from   w  w  w.  j a  va 2 s.  c  o m-->
</script>
<script>
  $(function() {
    var listElements = $("li");
    var firstEl = listElements.first();
    var lastEl = listElements.last();

    document.writeln("firstEl value:" + firstEl.html());
    document.writeln("firstEl length:" + firstEl.length);

    document.writeln("lastEl value:" + lastEl.html());
    document.writeln("firstEl length:" + firstEl.length);
  });
</script>
</head>
<body>
  <ul>
    <li>A</li>
    <li>B</li>
    <li>java 2s.com</li>
  </ul>
</body>
</html>

Click to view the demo





















Home »
  jQuery »
    jQuery Example »




Animation
DOM
Event
Form
List
Select
Style
Table
Utilities