PP.querySelector

Syntax

querySelector(domNode: HTMLElement, selector: String);

Parameters

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

selector. Selector that will be used to select elements.

Description

The querySelector method determines the first DOM node in wrapper of the elements selected by CSS selector.

Comments

This method returns an HTMLElement 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 the first DOM node in wrapper of the elements selected in the tree by CSS selector, and get internal text of the selected element:

// 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 element = PP.querySelector(dom, ".plainText");
console.log("The <" + element.nodeName + "> element contain text «" + element.innerText + "»");

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

The <P> element contains the "12" text

See also:

PP