Dom\Element::getElementsByClassName

(No version information available, might only be in Git)

Dom\Element::getElementsByClassName β€” Returns a collection of descendant elements that have the given classes

Опис

public function Dom\Element::getElementsByClassName(string $classNames): Dom\HTMLCollection

Returns a Dom\HTMLCollection of the descendants of this element, in document order, whose class attribute contains all the classes given in classNames. The element itself is never part of the collection.

ΠŸΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΈ

classNames

One or more class names separated by ASCII whitespace. An element only matches if it has every one of these classes, in any order.

Class names are compared case-sensitively, unless the document is in quirks mode, in which case the comparison is ASCII case-insensitive.

ЗначСння, Ρ‰ΠΎ ΠΏΠΎΠ²Π΅Ρ€Ρ‚Π°ΡŽΡ‚ΡŒΡΡ

Returns a Dom\HTMLCollection of the matching elements. The collection is empty if no element matches, or if classNames contains no class name, for example when it is an empty string or only whitespace.

Помилки/Π²ΠΈΠΊΠ»ΡŽΡ‡Π΅Π½Π½Ρ

Throws a ValueError if classNames contains a null byte.

ΠŸΡ€ΠΈΠΊΠ»Π°Π΄ΠΈ

ΠŸΡ€ΠΈΠΊΠ»Π°Π΄ #1 Dom\Element::getElementsByClassName() example

<?php

$dom = Dom\HTMLDocument::createFromString(
    '<!DOCTYPE html><body><div id="list">'
        . '<p class="item new">One</p>'
        . '<p class="item">Two</p>'
        . '<p class="Item">Three</p>'
        . '</div></body>',
    LIBXML_NOERROR
);

$list = $dom->getElementById('list');

foreach ($list->getElementsByClassName('new  item') as $element) {
    echo $element->textContent, "\n";
}

echo $list->getElementsByClassName('item')->length, "\n";

Поданий Π²ΠΈΡ‰Π΅ ΠΏΡ€ΠΈΠΊΠ»Π°Π΄ Π²ΠΈΠ²Π΅Π΄Π΅:

One
2

ΠŸΡ€ΠΎΠ³Π»ΡΠ½ΡŒΡ‚Π΅ Ρ‚Π°ΠΊΠΎΠΆ

οΌ‹add a note

User Contributed Notes

There are no user contributed notes for this page.