Home > Net >  How do i make my innerHTML content appear within an HTML element, i tried the following
How do i make my innerHTML content appear within an HTML element, i tried the following

Time:09-12

Its as simple as it gets, i want to change the text within <td> to be whatever the user enters in the prompt, i have tried many solutions. Such as putting the script element below body. Here is the java script code however it doesnt work although i assume everything is as it should.

var yourname = prompt("Enter your name");

document.getElementById("name").innerHTML = yourname;

Here is the HTML

<html><head>Cant figure this out</head>
<body>
<table>
      <tr>
        <td>Name</td>
    </tr>

    <tr>
         <td id = "Name"></td>
    </tr>
</table>
</body>
</html>```

CodePudding user response:

I see a couple of problems with the code:

  1. The html doesn't have a script-tag to use the javascript. Without that it won't load. To avoid these kind of problems please make the smallest code that have the problem and use copy-paste to get the exact code in questions.
  2. Name != name. The case of the id differs between the html and the javascript.
  3. You have additional characters last in the html: ```

I'm not a frontend developer and don't know if this will solve your current problem. But those issues should be handled either way.

CodePudding user response:

in your HTML you gave the an id of "Name", yet in the javascript script you are searching for an element with id "name". The id is case sensitive, so you would have to search for "Name", not "name".

  • Related