.toArray()

In this chapter you will learn:

  1. Use .toArray() to convert elements to array

Use .toArray() to convert elements to array

<!DOCTYPE html><!--from   j  a  va2 s.c o  m-->
<html>
    <head>
        <script src="http://java2s.com/style/jquery-1.8.0.min.js">
        </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

Next chapter...

What you will learn in the next chapter:

  1. Syntax and Description for .toggleClass()
  2. Toggle single class
  3. Toggle div element color