class Document
Note: in Sciter.JS class Document extends class Element class, global constant document represents root element of the document, so document.documentElement === document. Therefore all methods of Element class are available in document too.
Properties:
body
Element, <body> element reference.
head
Element, <head> element reference.
documentElement
Element, <html> element reference.
document === document.documentElement in Sciter
location
URL, location of the document.
URL
string, location of the document as a string.
readyState
string, values:
"interactive"- operational;"complete"- operational and finished loading resources;
globalThis
object, reference of global namespace object associated with this document.
All global variables and functions declared in the document scripts will be members of this object.
defaultView
In Sciter it returns the globalThis object.
Methods:
querySelector()
document.querySelector(selector)
parameters:
- selector - string, CSS selector
returns:
- Element, first element matching the selector;
- null if no element found;
$()
document.$(selector)
synonym of document.querySelector(selector)
querySelectorAll()
document.querySelectorAll(selector)
parameters:
- selector - string, CSS selector
returns:
- array of Element, list of all elements matching the selector;
- [], empty array if no element found;
$$()
document.$$(selector);
synonym of document.querySelectorAll(selector)
Enumerate all <span>s in the document
for(const span of document.$$("span"))
console.log(span);
getElementById()
document.getElementById(id)
parameters:
- id - string, ID of the element (without leading
#);
returns:
- Element, first element matching the selector;
- null if no element found;
createElement()
document.createElement(tag[,attributes])
parameters:
- tag - string, tag of the element ('"div"', '"span"', etc );
- attributes, object, optional, initial attributes of the element;
returns:
- Element, reference of the element.
createTextNode()
document.createTextNode(text)
parameters:
- text - string, text of the text node;
returns:
- Text, reference of the Text node.
createComment()
document.createComment(text)
parameters:
- text - string, text of the comment node;
returns:
- Comment, reference of the Comment node.
createDocumentFragment()
document.createDocumentFragment()
returns:
- Element, reference of the document fragment element.
createNodeIterator()
document.createNodeIterator(root[, whatToShow[, filter]])
parameters:
root, Element, the root element at which to begin the NodeIterator's traversal.
whatToShow - integer, optional, a bitmask created by combining the constant properties of NodeFilter:
Name Meaning NodeFilter.SHOW_ALL Shows all nodes NodeFilter.SHOW_ELEMENT Elements NodeFilter.SHOW_TEXT Text nodes NodeFilter.SHOW_COMMENT Comment nodes NodeFilter.SHOW_DOCUMENT Document nodes filter, function(node):integer, optional, the function will be called for each node satisfying the filter. The function shall return either one of these values:
Name Meaning NodeFilter.FILTER_ACCEPT accept the node for the iteartion NodeFilter.FILTER_REJECT reject the node and skip its content NodeFilter.FILTER_SKIP skip the node but walk through its content
returns:
- NodeIterator, reference of the node iterator.
createRange()
document.createRange([startNode,startIndex[,endNode,endIndex])
returns:
- Range, reference of new Range.
createDocument()
createHTMLDocument()
document.createDocument()
returns:
- Document, reference of new Document.
Methods (Sciter specific):
bindImage()
document.bindImage(url[, img])
This method associates the img with the arbitrary url so it can be used in CSS.
parameters:
- url - string, arbitrary URL;
- img - Image or null or undefined, image to associate with the URL:
- if img is ommited or undefined then the function returns existing image associated with the URL (if any);
- if img is null then the function removes binding set by previous
bindImage(url,img)call;
returns:
- Image, reference of an image.
- null if image was not found.
examples:
JS:
document.bindImage("in-memory:dynback");
CSS:
div {
/* uses image supplied by script: */
background-image: url("in-memory:dynback");
}
url()
document.url([relpath]) : string
returns absolute path of relpath using the document URL as a base.
If relpath is omitted the method returns url of the document itself.