getElementById()

Introduction

getElementById is a method for finding elements' reference based on a specified id in the current page. This method takes an id selector as the parameter and returns a reference to the corresponding element's reference. Please note that this reference does not allow background threads to hold the elements; background threads can only use this reference to inter thread call element methods across threads, and this reference does not affect the element's lifecycle.

Syntax

let element = lynx.getElementById(id);

Parameter

id

A String type, the id selector of the element to be obtained.

Return Value

Returns a NodeRef: If the corresponding element is found, a reference to the element is returned; if no corresponding element is found, null is returned.

Example

let ele = lynx.getElementById('id');
TIP

The reasons that getElementById may not select nodes are:

  • The ID selector is incorrect
  • The value of the ID selector depends on complex JS expressions, so that the value of the ID selector cannot be obtained at the first screen. At this time, if getElementById is too early (such as in ComponentDidMount), it may not find the node

Compatibility

LCD tables only load in the browser

Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.