On This Page
Elements
Properties
Query - DOM Access
Access underlying DOM elements and their properties directly.
Elements
el
$('selector').el();Returns the first DOM element in the collection.
Returns
First DOM element, or undefined if empty.
Usage
const element = $('button').el();element.focus();Example
get
$('selector').get();$('selector').get(index);Gets DOM elements from the Query object. Returns native DOM elements, not Query objects.
Parameters
| Name | Type | Description |
|---|---|---|
| index | number | Index of element to retrieve (supports negative) |
Returns
- With index: DOM element at the index, or
undefinedif out of range - Without index: Array of all DOM elements
Usage
Single Element
const first = $('p').get(0);const last = $('p').get(-1);All Elements
const elements = $('p').get();elements.forEach(el => console.log(el.textContent));Example
Properties
prop
$('selector').prop(name);$('selector').prop(name, value);Gets or sets a DOM property on elements. Unlike attributes, properties reflect the current state (e.g., checked, disabled, selectedIndex).
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | Property name |
| value | any | Value to set |
Returns
- Getting: Property value from the first element
- Setting: Query object (for chaining)
Usage
Get
const isChecked = $('input[type="checkbox"]').prop('checked');Set
$('input[type="checkbox"]').prop('checked', true);