Why doesn't it work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why doesn't it work?

https://code.sololearn.com/Wr2fLhsnBAfM/#html I can't understand how I can change the content of the heading into the clock

2nd Oct 2020, 3:49 PM
Karak10
Karak10 - avatar
5 Answers
+ 4
myArray[0].innerHTML = hour + ":" + minutes + ":" + seconds; Change myArray to myArray[0] Karak10 ByTagName returns an array....
2nd Oct 2020, 3:53 PM
Jayakrishna 🇮🇳
+ 2
var myArray = document.getElementsByTagName("h1"); selects a list of elements. That why you will be needed to say which with an index. myArray[0].innerHTML = hour + ":" + minutes + ":" + seconds;
2nd Oct 2020, 3:55 PM
JaScript
JaScript - avatar
+ 1
Not much know about it but tried this way and it is working...Karak10 i think may it can be done by other ways also.. $(function() { $("h1").click(function() { t = document.querySelector("h1"); this.innerHTML= Date() ; }); });
2nd Oct 2020, 7:16 PM
Jayakrishna 🇮🇳
+ 1
Karak10 Use a for loop for (var i = 0; i < myArray.length; i++) { myArray[i].innerHTML = hour + ':' + minutes + ':' + seconds; }
2nd Oct 2020, 9:14 PM
Ore
Ore - avatar
0
Jayakrishna🇮🇳 is there a way to make it so it applies to all headings then?
2nd Oct 2020, 4:54 PM
Karak10
Karak10 - avatar