
- jQuery - Home
- jQuery - Roadmap
- jQuery - Overview
- jQuery - Basics
- jQuery - Syntax
- jQuery - Selectors
- jQuery - Events
- jQuery - Attributes
- jQuery - AJAX
- jQuery CSS Manipulation
- jQuery - CSS Classes
- jQuery - Dimensions
- jQuery - CSS Properties
- jQuery Traversing
- jQuery - Traversing
- jQuery - Traversing Ancestors
- jQuery - Traversing Descendants
- jQuery References
- jQuery - Selectors
- jQuery - Events
- jQuery - Effects
- jQuery - HTML/CSS
- jQuery - Traversing
- jQuery - Miscellaneous
- jQuery - Properties
- jQuery - Utilities
- jQuery Plugins
- jQuery - Plugins
- jQuery - PagePiling.js
- jQuery - Flickerplate.js
- jQuery - Multiscroll.js
- jQuery - Slidebar.js
- jQuery - Rowgrid.js
- jQuery - Alertify.js
- jQuery - Progressbar.js
- jQuery - Slideshow.js
- jQuery - Drawsvg.js
- jQuery - Tagsort.js
- jQuery - LogosDistort.js
- jQuery - Filer.js
- jQuery - Whatsnearby.js
- jQuery - Checkout.js
- jQuery - Blockrain.js
- jQuery - Producttour.js
- jQuery - Megadropdown.js
- jQuery - Weather.js
jQuery Misc get() Method
The get() method in jQuery is used to retrieve the DOM elements matched by the jQuery object as an array or to access a specific element in the matched set.
When called without arguments, it returns an array of all the DOM elements in the matched set. When called with an index argument, it returns the specific DOM element at that index in the matched set.
Syntax
Following is the syntax of jQuery Misc get() method −
$(selector).get(index)
Parameters
Here is the description of the above syntax −
- index (optional): An integer representing the position of the element in the matched set (zero-based index).
Example 1
In the following example, we are using the jQuery Misc get() method get all matched DOM elements as an array −
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <script> $(document).ready(function(){ // Retrieve all <p> elements as an array var elementsArray = $("p").get(); document.write(elementsArray); }); </script> </head> <body> <p>Paragraph 1</p> <p>Paragraph 2</p> <p>Paragraph 3</p> </body> </html>
After executing the above program, the selected elements (Paragraph elements) will be returned as an array.
Example 2
In this example, we are retrieving and manipulating a specific element by index "1" −
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <script> $(document).ready(function(){ // Retrieve the second <p> element (index 1) var secondElement = $("p").get(1); secondElement.style.backgroundColor = "yellow"; }); </script> </head> <body> <p>Paragraph 1</p> <p>Paragraph 2</p> <p>Paragraph 3</p> </body> </html>
After executing, the selected element (Paragraph 2) will be highlighted with yellow background color.