I am trying to inject js variable with html page. Here, I need to show givenname as "shelly" on my html page. But I am not getting result from this. I used
Hello, . 。 Let's begin.
to give id as "givenname". And in js script code I have set inner,html to get name "shelly". The code of js is given as document.getElementById("givenname").innerHTML="shelly"; Can someone find what the problem is with this code. <.DOCTYPE html> <html lang="en"> <head> <title> Prectical2</title> <link href="styles2/style1,css" type="text/css" rel="stylesheet" /> </head> <body id="body"> <div id="content1"> <p>Hello. <b>id=givenname</b>. Let's begin?</p> </br> <div id="quiz"> <div id="N">Question N</div> <p>Question text should appear here</p> <div class="radio1"> <input type="radio" name="choices" id="A" value="A" /> <label for="A" id="choice-A">Choice A</label> </div> </br> <div class="radio2"> <input type="radio" name="choices" id="B" value="B" /> <label for="B" id="choice-B">Choice B</label> </div> </br> <div class="radio3"> <input type="radio" name="choices" id="C" value="C" /> <label for="C" id="choice-C">Choice C</label> </div> <div id="results"> <p>Your final score was.</p> </div> <div id ="quizsubmit"> <input type="button" value="Next" /> </div> </div> </div> </body> <script src="scripts/my-script.js" src="scripts/provided-script.js"> //alert(sucess) let fname="Shelly" document.getElementById("givenname");innerHTML = "fname"; </script> </html>
simply that?
let fname = 'Shelly'; document.querySelector('#givenname').textContent = fname;
<p>Hello, <b id="givenname"></b>. Let's begin.</p>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.