I have one paragraph in my html file. I need to write a Java Script function to show this paragraph, 5 seconds after opening the html file.
Asked
Active
Viewed 1,092 times
-2
-
4As you said, _you_ need to write a function. Please show what you have tried so far. – Teemu Nov 26 '17 at 17:46
-
Not so hard, please check: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout... – sinisake Nov 26 '17 at 17:48
-
1You may check setTimeout – ThinkGeek Nov 26 '17 at 18:14
-
@Teemu i wrote the answer. – Charity L. Meiners Nov 29 '17 at 21:54
1 Answers
0
I solved it here is solution :
var myVar=setInterval(function(){myTimer()},5000);
function myTimer()
{
var t="This is a Paragraph.";
document.getElementById("p").innerHTML=t;
}
<!DOCTYPE html>
<html>
<head>
<script src="7b.js"></script>
</head>
<body>
<p id="p"></p>
</body>
</html>
-
Only that the text in the paragraph is updated on every 5 seconds. Use `setTimeout` instead. – Teemu Nov 30 '17 at 05:42