Query - DOM Access API reference for Query methods that access DOM elements and properties box API Reference
Categories

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

NameTypeDescription
indexnumberIndex of element to retrieve (supports negative)

Returns

  • With index: DOM element at the index, or undefined if 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

NameTypeDescription
namestringProperty name
valueanyValue 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);

Example

Previous
DOM Traversal
Next
Events