Tag Archives: Hit the pit

Common error: uncaught typeerror: document.getElementsByClassName (…).addEventListener is not a function

Problems encountered in the development of native front end:

Uncaught TypeError: document.getElementsByClassName(...).addEventListener is not a function......

reason:

The

    selector did not select the element object correctly
    the document.getElementsByClassName (… )What is captured is the array
solution of the class name element

    document.getElementsByClassName (… )[0].addEventListener…
    Select the required element object through [0]