0
How would i dynamically seta JS variable into say an <h1> tag?
6 odpowiedzi
+ 4
Alternatively to writing a new element, using the sample you have in the HTML tab
<h1 id= "x"></h1>
any of these three sets locate and dynamically set the element's inner HTML. I'm using onload() because otherwise the [JS] tab would load before the document element is ready.
window.onload = function() {
var el = document.querySelector("#x");
el.innerHTML = x;
el = document.getElementsByTagName("h1")[0];
el.innerHTML = x;
el = document.getElementById("x");
el.innerHTML = x;
}
+ 3
Use the + operator to concatenate the values:
var x = 100;
document.write("<h1>" + x + "</h1>");
0
For what?
u can use JavaScript
0
maybe this will help? explain it better
0
thanks man