Hot answers tagged

8

Don't implicitly create global variables for (i = 0; uses a global i. Always declare variables before using them - in modern times, declare them with let or const, not var (which has too many problems, such as an unintuitive function scope rather than block scope, to be worth using nowadays) Iterators Or, even better, rather than iterating manually, invoke ...


6

Welcome to Code Review. The CSS looks quite good. I haven’t seen too many style sheets with color lightsalmon 😃. Below are some suggestions. Cache DOM references ”...DOM access is actually pretty costly - I think of it like if I have a bridge - like two pieces of land with a toll bridge, and the JavaScript engine is on one side, and the DOM is on the ...


6

Variables Always use a variable declaration when first declaring your variable. If you don't your variable will be put into the global scope, which is almost never what you want. It also makes it more clear that you don't want to re-assign to an already existing global variable. So for starting_day, for example, put a var, let, or const in front of it. HTML ...


3

In a CSS selector you can use a comma to select multiple items. var select = document.querySelectorAll("div.post-body.entry-content div h3 b"); for (i = 0; i < select.length; ++i) { var title = select[i].querySelectorAll("u, a")[0]; console.log (title.innerHTML); } This will get both u and a elements, but if only one of them ...


3

The JavaScript unnecessarily contains information that belongs in the style sheet. It would be much easier to have the JavaScript simply set/remove a class (for example, on the body) and put the styles into the style sheet. function openav() { document.body.classList.add("open-nav"); } function closenav() { document.body.classList.remove(&...


3

Spacing While spacing doesn't matter in JavaScript, some lines have more space than needed. For example, on this line, there are two spaces after the assignment operator: var select = document.querySelectorAll("div.post-body.entry-content div h3 b"); ^ One space in that spot would be fine. Technically no space is required but ...


Only top voted, non community-wiki answers of a minimum length are eligible