[CODE]
<html>
<head>
<script>
document.getElementById(“para1″).innerHTML=”welcome to Ratan IT”;
</script>
</head>
<body> <p id=”para1″> welcome </p> </body>
</html>
[/CODE]
Talk Programming , Career, Mental Health, Talk Personal Finance ❤️ Post a query and receive responses ✅
Post a query and receive responses. Ask anything, Ask Mitra ❤️
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
<html>
<head>
</head>
<body>
<p id=”para1″> welcome </p>
</body>
<script>
document.getElementById(“para1”).innerHTML = “welcome to Ratan IT”;
</script>
</html>
Your script tag should be after body not in head tag
Your script is not working due to you using an inline script before the body tag which is not able to get the get p tag with para1 id.
If you want to work the script then you have to keep the script below the targeted tags or simply keep it in the last of the body tag.
I will suggest you use external javascript rather than inline javascript. Example given:
“””
file: index.html
file: script.js
“””
here the script is kept below the body tag but if you want to add a script tag in the head then you can use defer attribute which runs after the full document load.
eg: <script src=”script.js” defer></script>
https://playcode.io/html/
you can try the code here.
Try this:
While inserting inline JavaScript the <script> tag should be used inside the body tag