Skip to main content

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.

Element, <head> element reference.

documentElement

Element, <html> element reference.

note

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.

note

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)

tip

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:

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:

    NameMeaning
    NodeFilter.SHOW_ALLShows all nodes
    NodeFilter.SHOW_ELEMENTElements
    NodeFilter.SHOW_TEXTText nodes
    NodeFilter.SHOW_COMMENTComment nodes
    NodeFilter.SHOW_DOCUMENTDocument 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:

    NameMeaning
    NodeFilter.FILTER_ACCEPTaccept the node for the iteartion
    NodeFilter.FILTER_REJECTreject the node and skip its content
    NodeFilter.FILTER_SKIPskip the node but walk through its content

returns:

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.