Documentation

DOMObject
in package
implements ArrayAccess, Countable, Iterator

This class is used to represent a results set of matched elements, in much the same way as a jQuery array works. Any methods supported by DOMElement can be called on a DOMObject list.

Interfaces, Classes, Traits and Enums

ArrayAccess
Countable
Iterator

Table of Contents

$container  : mixed
$index  : mixed
__call()  : This
Magic method for function calls, this can be used to call any methods supported by DOMElement on the entire result set stored in this DOMObject set
__construct()  : mixed
Constructor. This should never be invoked outside of DOMElement
__get()  : mixed
__toString()  : string
Returns this object as a HTML fragment string.
addClass()  : DOMObject
Adds class(es) to all elements within this set
after()  : DOMObject
Inserts conmtent after the elements within this set
append()  : DOMObject
Appends content inside the elements within this set
attr()  : string|DOMObject
Method for working with attributes on this set
before()  : DOMObject
Inserts conmtent before the elements within this set
children()  : DOMObject
Returns this sets children, or if a selector is supplied, only children of this set which match the selector
clear()  : DOMObject
Empties all elements in this set by removing all the elements children, equivalent to jQuery's empty method - empty is a reserved word in PHP.
closest()  : DOMObject
Returns closest ancestors of this set which matches the given selector. Please note this will NOT work on the document element presently
contains()  : mixed
contents()  : DOMObject
Returns all direct child elements of this set
count()  : int
css()  : DOMQueryResutls|string|null
Gets or sets inline styles on this set. Please note that this function, unlike jQuery, cannot be used to get computed styles. Only inline styles are supported.
current()  : mixed
data()  : string|DOMObject
Method for working with data- attributes on this set
duplicate()  : DOMObject
Returns a deep clone of all elements in this set, equivalent to jQuery's clone method - clone is a reserved word in PHP
each()  : DOMObject
Executes the supplied callback on the elements in this result set
filter()  : DOMObject
Filters this result set using the given subject
find()  : DOMObject
Finds any descendant elements which match the supplied CSS selector within this set.
first()  : DOMElement|null
Returns the first result in this set, or null if the set is empty
following()  : DOMObject
Returns the following siblings of this sets elements, optionally taking a selector to match against. PLEASE NOTE that this is the equivalent of jQuery's "next". "next" is implemented by the Iterator interface, and cannot be used. Please use following instead of next.
hasClass()  : bool
Tests if the specified class exists on at least one elements class attribute wihtin this set
hide()  : DOMObject
Hides elements within this set with inline CSS
html()  : DOMObject|string
Gets the HTML of the first node in the set, or sets the HTML of all nodes in the set
import()  : mixed
Imports the supplied subject and appends it to this set. Noop when this set is empty.
is()  : bool
Checks if any element within this set matches the supplied selector
isDocument()  : bool
Checks if this object contains the document exclusively
key()  : mixed
last()  : DOMElement|null
Returns the last result in this set, or null if the set is empty
next()  : void
offsetExists()  : bool
offsetGet()  : mixed
offsetSet()  : void
offsetUnset()  : void
parent()  : DOMObject
Returns the direct parents of all elements within this set
prepend()  : DOMObject
Prepends content inside the elements within this set
prev()  : DOMObject
Returns the previous siblings of this sets elements, optionally taking a selector to match against
prop()  : string|DOMObject
Method for working with props (eg checkbox and radio)
remove()  : DOMObject
Removes all elements within this set from the DOM tree
removeAttr()  : mixed
Removes the named attribute
removeClass()  : DOMObject
Removes the specified class from all elements within this set
replaceWith()  : DOMObject
reverse()  : mixed
rewind()  : void
show()  : DOMObject
Unhides elements within this set by removing inline CSS
siblings()  : DOMObject
Returns all siblings of elements within this set, optionally only siblings which match the provided CSS selector
text()  : DOMObject|string
Gets the text of all elements in the set, or sets the tewxt of all elements in the set
toArray()  : mixed
val()  : DOMQueryResult|string|null
Gets or sets the value of form elements
valid()  : bool
wrap()  : DOMObject
Wraps this set with the specified element or set, then replaces the elements with the wrapper. This does not presently support a function as input, like it's jQuery counterpart. If this set only contains a single node and $template is a DOMElement, $template will be injected directly into the DOM. If this set contains multiple elements then the wrapper will be cloned. If $template is a DOMObject, only the first element will be used.
wrapInner()  : DOMElement
Wraps the contents of this set with the specified element or set. This does not presently support a function as input, like it's jQuery counterpart. If this set only contains a single node and $template is a DOMElement, $template will be injected directly into the DOM. If this set contains multiple elements then the wrapper will be cloned. If $template is a DOMObject, only the first element will be used.
implicitOwnerDocumentCast()  : DOMDocument|null

Properties

Methods

__call()

Magic method for function calls, this can be used to call any methods supported by DOMElement on the entire result set stored in this DOMObject set

public __call(string $name, array<string|int, mixed> $arguments) : This
Parameters
$name : string

The name of the method to call

$arguments : array<string|int, mixed>

The arguments which will be passed on to the corresponding method on DOMElement

Tags
see
DOMElement

for a list of supported methods

Return values
This

results set for functions which return $this (eg attr), a new results set for functions which return result sets (eg find)

__construct()

Constructor. This should never be invoked outside of DOMElement

public __construct([mixed $arr = null ]) : mixed
Parameters
$arr : mixed = null
Return values
mixed

__get()

public __get(mixed $name) : mixed
Parameters
$name : mixed
Return values
mixed

__toString()

Returns this object as a HTML fragment string.

public __toString() : string
Return values
string

Elements in this object rendered to a HTML string fragment

addClass()

Adds class(es) to all elements within this set

public addClass(string $name) : DOMObject
Parameters
$name : string

The classname

Return values
DOMObject

This set, for method chaining

after()

Inserts conmtent after the elements within this set

public after(DOMElement|DOMObject|array<string|int, mixed>|string $arg) : DOMObject
Parameters
$arg : DOMElement|DOMObject|array<string|int, mixed>|string

The element(s) or text to insert

Tags
throws
Exception

When the supplied argument is not a DOMElement, DOMObject, array or string

throws
Exception

When an array is supplied with a non-DOMElement element

Return values
DOMObject

This set, for method chaining

append()

Appends content inside the elements within this set

public append(DOMElement|DOMObject|array<string|int, mixed>|string $subject) : DOMObject
Parameters
$subject : DOMElement|DOMObject|array<string|int, mixed>|string

The content to insert, can be an element, an array or result set of elements, or a string

Tags
throws
Exception

When the supplied argument is not a DOMElement, DOMObject, array or string

throws
Exception

When an array is supplied with a non-DOMElement element

Return values
DOMObject

This set, for method chaining

attr()

Method for working with attributes on this set

public attr(mixed $arg[, null|string $val = null ]) : string|DOMObject
Parameters
$arg : mixed
$val : null|string = null

A string, if the first argument is a string, or NULL if the first argument is an array

Tags
throws
Exception

When $arg is not supplied

throws
Exception

When first argument is neither a string nor an array

throws
Exception

When the first argument is a string, and the second argument is provided but not scalar

throws
Exception

When the first argument is a key value array, but the second argument is also set

throws
Exception

When the supplied key value array has a non-string key

throws
Exception

When the supplied key value array has a non-scalar value

Return values
string|DOMObject

A string when retrieving data, this set for method chaining when setting

before()

Inserts conmtent before the elements within this set

public before(DOMElement|DOMObject|array<string|int, mixed>|string $arg) : DOMObject
Parameters
$arg : DOMElement|DOMObject|array<string|int, mixed>|string

The element(s) or text to insert

Tags
throws
Exception

When the supplied argument is not a DOMElement, DOMObject, array or string

throws
Exception

When an array is supplied with a non-DOMElement element

Return values
DOMObject

This set, for method chaining

children()

Returns this sets children, or if a selector is supplied, only children of this set which match the selector

public children([string $selector = null ]) : DOMObject
Parameters
$selector : string = null

The CSS selector to match

Return values
DOMObject

Any children of this set which match the selector, or all children if no selector is specified

clear()

Empties all elements in this set by removing all the elements children, equivalent to jQuery's empty method - empty is a reserved word in PHP.

public clear() : DOMObject
Return values
DOMObject

This set, for method chaining

closest()

Returns closest ancestors of this set which matches the given selector. Please note this will NOT work on the document element presently

public closest(string $selector) : DOMObject
Parameters
$selector : string

The CSS selector to match

Tags
throws
Exception

When $selector is empty

Return values
DOMObject

The results set of ancestors matching $selector

contents()

Returns all direct child elements of this set

public contents() : DOMObject
Return values
DOMObject

The children of this set

count()

public count() : int
Return values
int

css()

Gets or sets inline styles on this set. Please note that this function, unlike jQuery, cannot be used to get computed styles. Only inline styles are supported.

public css([array<string|int, mixed>|string|null $arg = null ][, mixed $val = DOMDocument::UNDEFINED ]) : DOMQueryResutls|string|null
Parameters
$arg : array<string|int, mixed>|string|null = null

An array of properties to set, a or string to get from the first element in the set

$val : mixed = DOMDocument::UNDEFINED
Tags
throws
Exception

When the supplied argument is neither a string nor an array

Return values
DOMQueryResutls|string|null

Will return this set for method chaining if $arg is an array, returns the CSS property value as a string if $arg is a string, returns null if $arg is a string and $val is not supplied, and the set is empty

current()

public current() : mixed
Return values
mixed

data()

Method for working with data- attributes on this set

public data([null|string|array<string|int, mixed> $arg = null ][, null|string $val = null ]) : string|DOMObject
Parameters
$arg : null|string|array<string|int, mixed> = null

If both arguments are null / not provided, this function will return all data- attributes as an associative array. If a string is provided, it will be treated as a name and the value of the relevant data- attribute will be returned. If an array is provided, it will be used to set multiple data- attributes on the set.

$val : null|string = null

A second argument, this can only be used if $arg is a string

Tags
throws
Exception

When $arg is null, but $val is non-null. This is an invalid combination of arguments

throws
Exception

When $arg is a string, but $val is not a string or null

throws
Exception

When $arg is an array of key value pairs to set, but $val is not null

throws
Exception

When the combination of arguments supplied is invalid, or one or more types in the arguments are invalid

Return values
string|DOMObject

A string when retrieving data, this set for method chaining when setting data

duplicate()

Returns a deep clone of all elements in this set, equivalent to jQuery's clone method - clone is a reserved word in PHP

public duplicate() : DOMObject
Return values
DOMObject

The cloned element

each()

Executes the supplied callback on the elements in this result set

public each(callable $callback) : DOMObject
Parameters
$callback : callable

Any callable function

Tags
throws
Exception

When the supplied argument is not callable

Return values
DOMObject

This result set, for method chaining

filter()

Filters this result set using the given subject

public filter(string|callable $subject) : DOMObject
Parameters
$subject : string|callable

The subject to filter with. A string will be interpreted as a CSS selector, a callback can be used to implement custom filtering logic.

Tags
throws
Exception

When the supplied subject is neither a string nor callable

Return values
DOMObject

The filtered result set

find()

Finds any descendant elements which match the supplied CSS selector within this set.

public find(string $selector) : DOMObject
Parameters
$selector : string

The CSS selector

Return values
DOMObject

The result set matching the specified selector

first()

Returns the first result in this set, or null if the set is empty

public first() : DOMElement|null
Tags
todo

Review this, it should return a results set, should it be any empty array on an empty set? I expect so

Return values
DOMElement|null

The first element in the set, or null if the set is empty

following()

Returns the following siblings of this sets elements, optionally taking a selector to match against. PLEASE NOTE that this is the equivalent of jQuery's "next". "next" is implemented by the Iterator interface, and cannot be used. Please use following instead of next.

public following([string|null $selector = null ]) : DOMObject
Parameters
$selector : string|null = null

A CSS selector to match the sibling against, or null to get the sibling immediately previous to this element

Return values
DOMObject

Set of the matching elements

hasClass()

Tests if the specified class exists on at least one elements class attribute wihtin this set

public hasClass(string $name) : bool
Parameters
$name : string

The classname

Return values
bool

FALSE if no nodes in this set have the specified classname, TRUE if at least one node does

hide()

Hides elements within this set with inline CSS

public hide() : DOMObject
Return values
DOMObject

This set, for method chaining

html()

Gets the HTML of the first node in the set, or sets the HTML of all nodes in the set

public html([string|null $html = null ]) : DOMObject|string
Parameters
$html : string|null = null

Sets the HTML for all elements in the set if $html is a string, gets the HTML of the first element in this set if null is supplied

Return values
DOMObject|string

This set for method chaining if $html is not null, the HTML string representing the first element in this set if $html is null

import()

Imports the supplied subject and appends it to this set. Noop when this set is empty.

public import(mixed $subject) : mixed
Parameters
$subject : mixed
Return values
mixed

is()

Checks if any element within this set matches the supplied selector

public is(string $selector) : bool
Parameters
$selector : string

The CSS selector

Return values
bool

TRUE if this set contains an element which matches the supplied selector, FALSE otherwise

isDocument()

Checks if this object contains the document exclusively

public isDocument() : bool
Return values
bool

TRUE if this set contains the document exclusively

key()

public key() : mixed
Return values
mixed

last()

Returns the last result in this set, or null if the set is empty

public last() : DOMElement|null
Tags
todo

Review this, it should return a results set, should it be any empty array on an empty set? I expect so

Return values
DOMElement|null

The last element in the set, or null if the set is empty

next()

public next([mixed $arg = null ]) : void
Parameters
$arg : mixed = null
Return values
void

offsetExists()

public offsetExists(mixed $offset) : bool
Parameters
$offset : mixed
Return values
bool

offsetGet()

public offsetGet(mixed $offset) : mixed
Parameters
$offset : mixed
Return values
mixed

offsetSet()

public offsetSet(mixed $offset, mixed $value) : void
Parameters
$offset : mixed
$value : mixed
Return values
void

offsetUnset()

public offsetUnset(mixed $offset) : void
Parameters
$offset : mixed
Return values
void

parent()

Returns the direct parents of all elements within this set

public parent([string $selector = null ]) : DOMObject
Parameters
$selector : string = null

The CSS selector to match

Return values
DOMObject

The results set of direct parents matching $selector (if specified)

prepend()

Prepends content inside the elements within this set

public prepend(DOMElement|DOMObject|array<string|int, mixed>|string $subject) : DOMObject
Parameters
$subject : DOMElement|DOMObject|array<string|int, mixed>|string

The content to insert, can be an element, an array or result set of elements, or a string

Tags
throws
Exception

When the supplied argument is not a DOMElement, DOMObject, array or string

throws
Exception

When an array is supplied with a non-DOMElement element

Return values
DOMObject

This set, for method chaining

prev()

Returns the previous siblings of this sets elements, optionally taking a selector to match against

public prev([string|null $selector = null ]) : DOMObject
Parameters
$selector : string|null = null

A CSS selector to match the sibling against, or null to get the sibling immediately previous to this element

Return values
DOMObject

Set of the matching elements

prop()

Method for working with props (eg checkbox and radio)

public prop(string|array<string|int, mixed> $name[, mixed $value = null ]) : string|DOMObject
Parameters
$name : string|array<string|int, mixed>

Name of the property, usually "checked"

$value : mixed = null
Return values
string|DOMObject

$this DOMObject for method chaining

remove()

Removes all elements within this set from the DOM tree

public remove() : DOMObject
Return values
DOMObject

This set, for method chaining

removeAttr()

Removes the named attribute

public removeAttr(string $name) : mixed
Parameters
$name : string

Name of the attribute to remove

Return values
mixed

removeClass()

Removes the specified class from all elements within this set

public removeClass(string $name) : DOMObject
Parameters
$name : string

The classname

Return values
DOMObject

This set, for method chaining

replaceWith()

public replaceWith(mixed $subject) : DOMObject
Parameters
$subject : mixed
Tags
throws
Exception

When the supplied argument is not a DOMElement, DOMObject, array or string

throws
Exception

When an array is supplied with a non-DOMElement element

Return values
DOMObject

This set, for method chaining

reverse()

public reverse() : mixed
Return values
mixed

rewind()

public rewind() : void
Return values
void

show()

Unhides elements within this set by removing inline CSS

public show() : DOMObject
Return values
DOMObject

This set, for method chaining

siblings()

Returns all siblings of elements within this set, optionally only siblings which match the provided CSS selector

public siblings([mixed $selector = null ]) : DOMObject
Parameters
$selector : mixed = null
Return values
DOMObject

The matching siblings, or all siblings if no selector is provided

text()

Gets the text of all elements in the set, or sets the tewxt of all elements in the set

public text([string|null $text = null ]) : DOMObject|string
Parameters
$text : string|null = null

Sets the value if a string is provided, gets if null is supplied

Return values
DOMObject|string

This set for method chaining if $text is not null, the textContent of all elements in the set if $text is null

toArray()

public toArray() : mixed
Return values
mixed

val()

Gets or sets the value of form elements

public val([string|null $value = null ]) : DOMQueryResult|string|null
Parameters
$value : string|null = null

NULL to get the value of this element, a string to set the value of this element

Return values
DOMQueryResult|string|null

When setting values, this DOMObject set is returned for method chaining. When getting, the value of the input, or null if no value is present

valid()

public valid() : bool
Return values
bool

wrap()

Wraps this set with the specified element or set, then replaces the elements with the wrapper. This does not presently support a function as input, like it's jQuery counterpart. If this set only contains a single node and $template is a DOMElement, $template will be injected directly into the DOM. If this set contains multiple elements then the wrapper will be cloned. If $template is a DOMObject, only the first element will be used.

public wrap(mixed $template) : DOMObject
Parameters
$template : mixed
Return values
DOMObject

This set, for method chaining

wrapInner()

Wraps the contents of this set with the specified element or set. This does not presently support a function as input, like it's jQuery counterpart. If this set only contains a single node and $template is a DOMElement, $template will be injected directly into the DOM. If this set contains multiple elements then the wrapper will be cloned. If $template is a DOMObject, only the first element will be used.

public wrapInner(mixed $template) : DOMElement
Parameters
$template : mixed
Return values
DOMElement

This element, for method chaining

Search results