skip to Main Content

Uncaught TypeError: planet.innerText is not a function

        .addEventListener("click",function() {
        let planet= document.getElementById("redplanet")  
        planet.innerText("Nothing to report");
        planet.classList.remove("alert");
        })
document.getElementById("greenplanet").classList.add("alert")

html code: “`

 So my js code isn't working in inspect it says that line 23 is not a function any solution to solve this?

2

Answers


  1. It is not a function. It is a property.

    Use

    planet.innerText = "Nothing to report";
    
    Login or Signup to reply.
  2. The error message is quite clear. DOMElement.innerText is not a function. You are supposed to use it as a property:

    const planet = document.getElementById('redplanet');
    planet.innerText = 'Hello world';
    

    A live example can be found here:
    https://jsfiddle.net/ga1ytz0j/

    For more information, please visit:
    https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search