+ 1
I want to add an automatic entry counter to this code. Can anyone help me?
https://code.sololearn.com/WuqZ0n7eh9Vv/?ref=app So this is my blog. I want to add a counter that automatically updates and displays on the webpage using js. Can somebody give me some code to help me?
3 Respostas
+ 3
function getEntryCount() {
return document.getElementsByClassName("entry").length;
}
window.onload = function(){
console.log(getEntryCount());
}
/*
you already wrote the function , I did minor adjustments.
Notes
whenever accessing DOM then we make sure to do so after the Dom is loaded , else we ll operate on an empty Dom.
hence any Dom Operations after the onload eventlistener
*/
+ 3
/*Daniel Cooper just pick anywhere in the html you wish to append it .
for example:
to set it in the footer we ll do like this inside onload eventlistener*/
document.querySelector("footer").textContent = "count : " + getEntryCount();
0
Thanks, but how can I add it to the page rather than the console?