+ 5
How to make HTML print based on a Javascript condition?
i just started experimenting in web, and i realize this question might seem menial to some veterans. How do i make a condition in JavaScript affect the output in HTML? for example- something like this (in JS) : i = 6 i += 1 and in HTML: if i = 7 <div id=i> I is 7 <div/> in short, i want HTML to print "I is 7" if i = 7 in JavaScript
5 Respuestas
+ 5
@Oliver, and how would i make HTML print the value of i?
+ 1
write this code in JS ; by this method you can change any value of element in your Html files.
document.getElementById("i").innerHtml = "Is is" +7;
+ 1
use js to define the innerHTML value of the div
if (i==7) {
document.getElementById("i").innerHTML = "i is 7";
}
0
You could use jQuery.
But if you want a simpler way of doing it:
You should use AngularJS!
0
@leigh html does not know variables, so the transfer from js variable to html code only work in the way you change the printed code with js (or other languages)