PP.querySelectorAll

Syntax

querySelectorAll(domNode: HTMLElement, selector: String);

Parameters

domNode. Root of the DOM tree in context of which you will select the elements.

selector. Selector to be used to select elements.

Description

The querySelectorAll method returns all DOM nodes selected from the tree by CSS selector.

Comments

This method returns an Array value.

Example

To execute the example, add a link to PP.js scenario file to HTML page. Create a DOM tree based on a specified string that contains HTML markup, then determine all DOM nodes in wrappers of the elements selected in the tree by CSS selector, and get internal text for each of the selected elements:

// Determine markup string
var markup = "<div><p class='plainText'>12</p><span class='plainText'>abc</span></div>";
// Transform markup to DOM node
var dom = PP.htmlToDOM(markup, False);
// Determine the first DOM node in the wrapper of the elements selected by selector
var elements = PP.querySelectorAll(dom, ".plainText");
for (var i = 0; i < elements.length; i++) {
    var element = elements[i];
    console.log("The <" + element.nodeName + "> element contains text «" + element.innerText + "»");
};

After executing the example the browser console displays internal text of all DOM elements selected by CSS selector:

The <P> element contains the "12" text

The <SPAN> element contains the "abc" text

See also:

PP