.get()

Description

.get() accepts a zero-based index as its argument and returns the element at that index.

Get list element by index

The following code shows how to get the list element by index.


<!DOCTYPE html>
<html>
    <head>
        <script src="http://java2s.com/style/jquery-1.8.0.min.js">
        </script>
        <script>
            $(function(){<!-- w ww  .ja  va 2 s .com-->
                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

The code above generates the following result.

.get()
Home »
  Javascript Tutorial »
    jQuery Reference »
      DOM
...
$("html tags")
.add()
.addClass()
.after()
.andSelf()
.append()
.appendTo()
.attr()
.before()
.children()
.clone()
.closest()
.contents()
.css()
.detach()
.filter()
.first()
.get()
.has()
.hasClass()
.height()
.html()
.index()
.innerHeight()
.innerWidth()
.insertAfter()
.insertBefore()
.is()
.last()
.map()
.next()
.nextAll()
.nextUntil()
.not()
.offset()
.offsetParent()
.outerHeight()
.outerWidth()
...