14
votes
Accepted
Lights on: playing with buttons in Javascript
I'll just start by looking at what you have, and then I'll get to your questions. (Edit: Seems I'm retreading a lot of what SirPython already covered. Didn't see that answer before I posted. Apologies ...
11
votes
Accepted
forEach and NodeList
The only purpose of this script appears to be to illustrate the use the Array.prototype.slice.call "idiom" and the forEach ...
9
votes
Lights on: playing with buttons in Javascript
HTML
In HTML, the property values should always be encased in ""s, even if the type is not necessarily intended to be a string. If needed, the JavaScript ...
9
votes
Accepted
Simple dice game - JavaScript MVC implementation
MVC thing is hard to be taken right. And yet it is the most popular (my guess) approach in the modern web development.
There are different ways to say what MVC means in particular application. I ...
8
votes
C++ Tree Class implementation
Some quick comments:
Const correctness
You really should make your code const correct.
For example at least these functions could be const declared:
...
8
votes
Accepted
Selecting elements from the DOM of a page
Don't implicitly create global variables for (i = 0; uses a global i. Always declare variables before using them - in modern ...
7
votes
Lights on: playing with buttons in Javascript
For a beginner, it isn't bad. There are some rough points to fix, but nothing serious!
Lets tackle by language:
HTML:
The first thing I've noticed is your doctype:
...
7
votes
Accepted
Create multiple divs inside a containing div
Descriptive names
As a global function name, generate is too vague: it should tell what it's generating, something like ...
7
votes
Showing "open" or "closed" based on the current time
The first bug is that you are misusing setInterval(). You should be passing a function, not the void result of the function, when calling ...
6
votes
New Game - Am I going down the right path for DOM manipulation?
Personally instead of using .find I prefer passing context to the jQuery selector like this;
...
6
votes
forEach and NodeList
Just two minor notes to add @Flambino's great answer:
Instead of x use intention-revealing names. What's the purpose of this variable? Name according to that. <...
6
votes
Updating Grid on Webpage (new version)
Overall it looks pretty clean,
I'd like to see some comments on the functions so I know what they do without having to read the code, you could use JSDoc for this.
I'd recommend explicitly using ...
6
votes
Accepted
Truncating text with jQuery but keep the HTML formatting
First of all, I would just like to say that this is a really good and useful function. From a Code Review standpoint, there are almost no errors in it that I know of. Here are a few things I found ...
6
votes
Accepted
Determine closest ancestor that has a certain HTML class
Extending native prototypes is a little iffy. Not that this should cause any problems, but in principle it's best to avoid. The reason is mostly that if everyone extend native prototypes, then you're ...
6
votes
Accepted
Evaluating an XPath with document.evaluate() to get an array of nodes
I don't see a method to directly turn it into an array -- Array.from doesn't work, eg. The best I could achieve was a little cleanup:
...
6
votes
Accepted
Platformer without canvas
Review of DOM game
Games coding is not easy and you have managed the fundamentals of a platformer, great work.
Unfortunately your game is technically flawed in a number of areas however first I will ...
6
votes
Accepted
Tic tac toe game in a web browser
Style and code
Numeric styles can be set using Number. eg modalParent.style.opacity = '1'; can be ...
6
votes
Accepted
Simple input class change with vanilla JS
Review
The biggest critique about the Javascript I have is that collapsedInput could be declared with const because it doesn't ...
6
votes
Accepted
Refactor JavaScript nested if-else
As already suggested, you can abstract common logic to a function:
...
5
votes
Implementing an algorithm that walks the DOM without recursion
Here is a solution that is about as concise as your recursive solution. (8 lines of code.)
...
5
votes
Updating Grid on Webpage
Just a couple of things that I really feel strongly about (didn't work line for line through your code though).
Seperation of logic and presentation
Yes, there is a ...
5
votes
Accepted
Horizontal menu for 3 items
Template
The first thing that comes into mind when building widgets is how the HTML is written. I'd avoid the HTML concatenated strings in JS. They're just so messy. I prefer templates instead, like ...
5
votes
Updating Grid on Webpage (new version)
Chris Thomson's answer makes some very good points about the overall quality, and Leopoldo Salvo's answer points out several hidden issues with the timer(s) and event handling. My comments will be ...
5
votes
Accepted
Updating Grid on Webpage (new version)
I would not hard code 'container', instead make it an attribute of gridOptions :
var options = {
....
containerClass = 'container',
....
}
I would ...
5
votes
Fix base64 data URI scripts function
Watch out!
jQuery is full of secrets. html method is not just a simple wrapper around innerHTML property.
Possible fail ...
5
votes
Accepted
Simple todo list
Don't pollute the global namespace. You have 1 variable and 3 functions all going into the global namespace. This is especially a problem because of the generic names you have. So they could be ...
5
votes
jQuery selector function in JavaScript
First off, you have a bug. On the line if (tagElemCollection[i].id != "") {, you used the != operator instead of the ...
5
votes
Filling in comment replies when link is clicked
jQuery's docs for .parent(): You can specify a selector to find a specific ancestor.
Or you can use the .parents() method to ...
5
votes
Accepted
5
votes
Accepted
HTML and JS to dynamically load, refresh, and execute JavaScript from external file
This code is very clean, and I believe that it is a very useful tool for any JavaScript developer.
This is not very efficient:
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
dom × 398javascript × 356
html × 112
jquery × 97
beginner × 45
css × 41
event-handling × 41
ecmascript-6 × 35
performance × 21
form × 21
animation × 16
php × 14
xml × 14
object-oriented × 13
game × 12
html5 × 12
java × 11
ajax × 10
datetime × 8
to-do-list × 8
recursion × 7
image × 7
typescript × 7
json × 6
timer × 6