Issue
Ok, let's say I have this HTML code, and I want to change the header from within the js code, how would I? I've tried several other solutions from other Q&As but they don't seem to work, either I'm brain dead or stuck. I want to change the header based on a variable, so something like:
header = variablexyz;
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.header {
padding: 60px;
text-align: center;
background: #1746c7;
color: white;
font-size: 50px;
}
</style>
</head>
<body>
<div class="header">
<h1>header</h1>
<p>-randomly generated username-</p>
</div>
<script src="script.js"></script>
</body>
</html>
Solution
This quite simple let header = document.getElementById('header') header.innerHTML = "Hello"
Please assign a class name or ID to your header <h1 id="idhere">
Answered By - Christian Lowe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.