get() Method to get the element by index - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:get


The get() method gets the DOM elements by the selector.


Parameter Require Description
index Optional. the matching elements to get (by index number)

The following code shows how to get the name and value of the first <p> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<script src=""></script>
        var x = $("p").get(0);
        $("div").text(x.nodeName + ": " + x.innerHTML);
    });/*  ww  w  .jav  a 2  s. c  om*/

<p>This is a paragraph</p>
<p>This is a paragraph 2</p>
<p>This is a paragraph 3</p>
<p>This is a paragraph 4</p>

<button>Get the p DOM element</button>



Related Tutorials