LANGUAGE » JAVASCRIPT » BROWSER

Elements

Retrieving

Property / MethodDescription
document.activeElementThe Element that currently has focus.
document.getElementById()An object reference to the identified element.
document.getElementsByClassName()A list of elements with the given class name.
document.getElementsByTagName()A list of elements with the given tag name.
document.getElementsByName()A list of elements with the given name.

Properties

PropertyDescription
Element.textContentA DOMString representing the text content of the node and its descendants.
Element.innerTextA DOMString representing the rendered text content of an element.
Element.innerHTMLA HTML or XML markup contained within the element.
Element.idA DOMString representing the id of the element.
Element.tagNameA String with the name of the tag for the given element.
Element.classListA DOMTokenList containing the list of class attributes.
Element.clientHeightA Number representing the inner height of the element.
Element.scrollHeightA Number representing the scroll view height of an element.
Element.scrollTopA Number representing number of pixels the top of the document is scrolled vertically.
Element.styleA CSSStyleDeclaration representing the declarations of the element's style attribute.
Input.valueA DOMString that contains the current value of the text entered into the text field.

Methods

MethodDescription
Element.clickClick an element.
Element.getBoundingClientRectGet size of an element and its position relative to the viewport.
Element.scrollByScrolls an element by the given amount.
Element.dispatchEventDispatch a new event (for example, a KeyboardEvent).

Emulate a Shift + Delete keypress:

js
function onClick(event) {
    const keydownEvent = new KeyboardEvent('keydown', {
        key: 'Delete',
        code: 'Delete',
        shiftKey: true,
        bubbles: true,
    });
    event.target.dispatchEvent(keydownEvent);
}