PP.getStyle

Syntax

getStyle(elem: HTMLElement, prop: String, toNumber: Boolean);

Parameters

elem. ID or DOM node of the element.

prop. Name of the property, for which you define the value.

toNumber. Indicates if style value is converted to a number. If this parameter is set to True, the method will try to convert style to a number, otherwise no such attempt is performed. In case the transformation failed, the method returns 0. This is an optional parameter, by default its value is not defined.

Description

The getStyle method determines property value for style of specified DOM element.

Comments

To ensure correct performance of the method, the specified DOM element must be included in DOM tree of the document.

Example

To execute the example, add a link to PP.js scenario file to HTML page. Determine margin value for the created DOM element:

// Determine a string with markup
var markup = "<div id='main' style=\"margin: 20px\"><p>12</p></div>";
// Transform markup  to DOM node
var dom = PP.htmlToDOM(markup, False);
// Add DOM node to document
document.body.appendChild(dom);
// Get value of external margin for the created element
var style = PP.getStyle(dom, "margin", False);
if (PP.isPrimitive(style)) {
    console.log("margin: " + style);
} else {
    console.log("Element style is not determined.");
};

After executing the example the browser console displays value of the margin style property for the div block:

margin: 20px

See also:

PP