+ 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

26th May 2017, 12:49 PM
Leigh E. O.
Leigh E. O. - avatar
5 Respuestas
+ 5
@Oliver, and how would i make HTML print the value of i?
26th May 2017, 1:09 PM
Leigh E. O.
Leigh E. O. - avatar
+ 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;
26th May 2017, 12:55 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 1
use js to define the innerHTML value of the div if (i==7) { document.getElementById("i").innerHTML = "i is 7"; }
26th May 2017, 12:56 PM
Oliver
0
You could use jQuery. But if you want a simpler way of doing it: You should use AngularJS!
26th May 2017, 12:51 PM
Jonas Geiler
Jonas Geiler - avatar
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)
26th May 2017, 1:35 PM
Oliver