Get first selected

Description

The following code shows how to get first element in query set.

Example


<html>
<head>
<script type="text/javascript"
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {<!--from   ww  w. jav a2s.c om-->
    var mappedItems = $("li").map(function(index) {
      var data = $("<li>").text($(this).text()).get(0);
      data = [ data, $("<li>").get(0) ];
      $(data[0]).append("*");
      return data;
    });
    $("#results").append(mappedItems);
  });
</script>
</head>
<body>
<body>
  <ul>
    <li>A</li>
    <li>B</li>
    <li>C</li>
  </ul>
  <ul id="results">
  </ul>
</body>
</html>

Click to view the demo





















Home »
  jQuery »
    jQuery Example »




Animation
DOM
Event
Form
List
Select
Style
Table
Utilities