problem with textContent in Javascript.

0

I am learning Javascript and for this I am studying the book "Javascript & Jquery by Jon Duckett", I would like to know if I'm doing something wrong, according to the book you should modify the html text and place the content of the javascript file instead of this through the textContent or that I think, but nothing happens, I would like to know if someone can help me with this, thanks.

 
    var greeting = 'Howdy ';
    var name = 'Molly';

    var welcomeMessage = greeting + name + '!';
    var el = document.getElementByld('greeting');
    el.textContent = welcomeMessage;
<!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>Document</title>

</head>

<body>
  <h1>Elderflower</h1>
  <div id="content" onclick="">
    <div id="greeting" class="message">Hello
      <span id="name">friend</span>!
    </div>
  </div>
</body>

</html>
    
asked by Agusavendaño 21.12.2018 в 02:54
source

2 answers

0

What I see is that you have an error in the line of code:

var el = document.getElementByld('greeting');

It should be:

var el = document.getElementById('greeting');

You are using a l instead of a I .

    
answered by 21.12.2018 / 03:54
source
0

You need to call your script

!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>Document</title>
  <script src="path/to/script.js"></script> <!-- AQUI SE LLAMA AL SCRIPT -->
</head>

<body>
  <h1>Elderflower</h1>
  <div id="content" onclick="">
    <div id="greeting" class="message">Hello
      <span id="name">friend</span>!
    </div>
  </div>
</body>

</html>
    
answered by 21.12.2018 в 03:09