1

i have no idea about this error, because i just checked all of other topics and didn't get result.

let demo = document.getElementById("#demo");
demo.innerText("yo");
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Pract</title>
</head>
<body>
    <script src="javascript.js"></script>
    <p id="demo"></p>
</body>
</html>
melpomene
  • 84,125
  • 8
  • 85
  • 148
Tafhim
  • 41
  • 1
  • 1
  • 5

1 Answers1

3

//currently your id is demo

let demo = document.getElementById("demo");
demo.innerText="yo";

///if your id is  #demo use this
let demo2 = document.getElementById("#demo");
demo2.innerText="yolo";
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Pract</title>
</head>
<body>
    <script src="javascript.js"></script>
    <p id="demo"></p>
    <p id="#demo"></p>
</body>
</html>

As your id is demo, not #demo, you need to write your code like this:

let demo = document.getElementById("demo");  // don't use #
demo.innerText = "yo";  // Also change innerText like this

And for changing innerText property have a look at docs. innerText is not a method.

melpomene
  • 84,125
  • 8
  • 85
  • 148
Shubham Dixit
  • 9,242
  • 4
  • 27
  • 46
  • 1
    A bit more explanation wouldn't be a bad thing (rather than just comments on the end of the lines) – freefaller Jun 04 '19 at 10:25
  • its true, but didn't solve main error – Tafhim Jun 04 '19 at 10:30
  • 1
    @Tafhim That's because your ` – melpomene Jun 04 '19 at 10:33