Convert elements to array with .toArray() in jQuery

Description

The following code shows how to convert elements to array with .toArray().

Example


<!DOCTYPE html>
<html>
<head>
<script
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
  <!--from  ww w.  ja  va2  s. co  m-->
</script>
<script>
  $(function() {
    var winners = $("#winners li").toArray();
    winners = winners.reverse();
    for (var i = 0, test = winners.length; i < test; i++) {
      document.writeln(winners[i].innerHTML);
    }
  });
</script>
</head>
<body>
  <ol id="winners">
    <li>A</li>
    <li>B</li>
    <li>C</li>
    <li>D</li>
    <li>java2s.com</li>
    <li>F</li>
    <li>G</li>
  </ol>
</body>
</html>

Click to view the demo





















Home »
  jQuery »
    jQuery Example »




Animation
DOM
Event
Form
List
Select
Style
Table
Utilities