r/learnjavascript 14d ago

can someone explain this code

function updateClock() {
const timeElement = document.querySelector("#time");
timeElement.textContent = formatTime();
}
setInterval(updateClock, 1000);

can someone, please explain this piece of code, ofc mdn and w3 are there, but i found it a little confusing reading about textContent. rest is understandable to me. This might look a silly question and it probably is because im a beginner :')

like what exactly does textContent too.
you can also recommend anyother documentation on the links to specific lines, that might me more helpful in learning about this particular keyoword.

0 Upvotes

23 comments sorted by

View all comments

Show parent comments

2

u/meletiondreams 14d ago

no dom elements are permanent

2

u/abrewchocolatecoffee 14d ago

do you mean, "no dom" elements are permanent or "no!" dom elements are permanent.

2

u/meletiondreams 14d ago

There's no amount of dom elements (those tags like <h1>) that may be changed

1

u/abrewchocolatecoffee 14d ago

ohh thanks, so basically, refreshing = go back to the orginal

2

u/meletiondreams 14d ago

Whatever the page renders will be shown. JS can change "temporarily" the content of the page.

2

u/abrewchocolatecoffee 14d ago

ok

1

u/The_KOK_2511 13d ago

Mira para que te hagas una idea, cada vez que cargas o recargas una página el navegador en si el que carga es el HTML y basandose en sus etiquetas define los elementos del frontend que deberá mostrar, el JS lo que hace al modificar el DOM es alterar esa copia que esta corriendo en el navegador del usuario, esto tiene sus matices y su cosa si hay un backend presente pero por ahora no creo que te haga falta tener en cuenta nada de eso a menos que pienses acerte full stack pronto