Skip to main content
Share Your Experience: Take the 2024 Developer Survey
11 votes
Accepted

Using regex to replace strange characters

RegEx Improvements The regex can be shortened by using case-insensitive match with i flag. We can remove the characters which are added as both lowercase and ...
Tushar's user avatar
  • 3,002
10 votes

Selecting checkboxes based on URL parameters

Extract the chk parameter value from location.search and use a "lookup table" object: ...
woxxom's user avatar
  • 1,952
9 votes
Accepted

Changing color on button click

...
Malachi's user avatar
  • 28.6k
9 votes

jQuery navbar scrollTop position

I would write this like: ...
Dan Cantir's user avatar
8 votes

Changing color on button click

It would be better to use CSS for styling and manipulate a class with JS (using the jQuery library, in this case). ...
Guest's user avatar
  • 81
8 votes

Gallery of employees with dynamic filtering

Make a lookup table. Then access by index: var expertises = ["asset", "insurance", "wealth"]; expertise = expertises[$(this).index()]; showConsultant(); If you'...
Pimgd's user avatar
  • 22.3k
7 votes

Overriding the mouseout handler for an image when a button is clicked

It is bad practice as you add a new handler each time your event is fired. To better understand this, try this: ...
Koch Maxence's user avatar
7 votes

Restrict HTML input field to decimal

I think that you are going about this the wrong way. Rather than thinking of what you should remove, you should think of what you should match. You are only allowing zero to two digits before a ...
Peilonrayz's user avatar
  • 43.4k
7 votes

Contra - 30 More Lives

One thing you could improve is to remove the jQuery dependency and just use addEventListener directly. This should be fine as all modern browsers support this ...
Joseph's user avatar
  • 25.1k
7 votes
Accepted

Adding multiple rows in an HTML table using jQuery

I'd do it like this: ...
SWa's user avatar
  • 186
7 votes
Accepted

jQuery navbar scrollTop position

I have a few questions to ask about your code, before I dive in: Why are you storing the header's location? Isn't the header supposed to be on the top? If it is at the top, isn't it at position 0? If ...
Ismael Miguel's user avatar
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 ...
Guy Incognito's user avatar
7 votes

Selecting checkboxes based on URL parameters

First of all, it would help tremendously if you named the URL parameter values and the form element IDs consistently. Why do you have chk=webdes-check ...
200_success's user avatar
7 votes

JS Function warning before closing browser

If you don't need the confirmExit function anywhere else, you can just assign it to to window.beforeunload. ...
Cedric's user avatar
  • 331
6 votes

First HTML5 game: Snake

You did really well with readability and documentation. On the design side, I would personally have the score off to the side and not in the middle, although it isn't that big of a deal. I would also ...
Confettimaker's user avatar
6 votes
Accepted

jQuery functions to add corresponding entries of lists

I think you could rewrite the code in a shorter way. You can write the calculateSum# function to be generic. This you can do by providing the selector or directly ...
Mario Santini's user avatar
6 votes
Accepted

Button click handlers for a JavaScript text-based adventure game

You are falling into a conceptual trap of trying to define javascript behaviors for each element on the page by numbering each and every one with a different id or class name (i.e. ...
Mike Brant's user avatar
  • 9,608
6 votes
Accepted

Add/Remove class on scroll depending on scroll length

The code can made very short. ...
Tushar's user avatar
  • 3,002
6 votes

JavaScript Rain

Naming If you need comment to explain a variable then the variable is not named correctly. Variable nbDrop and functions ...
Tushar's user avatar
  • 3,002
6 votes

Interactive small town

JavaScript The loop that generates people - an expensive bridge to cross ”...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, ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
6 votes

Selecting checkboxes based on URL parameters

I don't do javascript but what I noticed right away is that you are doing url[1].toLowerCase() for each if and ...
Heslacher's user avatar
  • 50.4k
6 votes
Accepted

Load JSON from server using jQuery and display it in html5

Some ideas: #1- I suggest using .map().join() or even better .reduce() which is more ...
Sergio's user avatar
  • 353
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 ...
Blindman67's user avatar
  • 22.1k
6 votes
Accepted

Three versions of a counting-up timer in JavaScript

Performance is not a significant concern, since all three callbacks have very little code, and they execute only once per second. Rather, you should aim for clarity. In my opinion, Version 1 is ...
200_success's user avatar
6 votes
Accepted

Turtle Doodle (my first web app)

I would limit my review to db.php file only. First of all, I see you made use of some of my advises already, probably visited some of my articles. Sadly, not all recommendations are followed, but that'...
Your Common Sense's user avatar
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 ...
sineemore's user avatar
  • 1,785
5 votes

Refreshing / Cycling through a parsed RSS feed every 5 mins

I know this code is more than four years old and you haven't been on CR since then but maybe it will help somebody else. String concatenation and adding HTML elements The code adds a lot of HTML via ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
5 votes
Accepted

JavaScript implementation of Conway's Game of Life

I cloned your code and created a website using the GitHub repo that I created with it so you can see some of the other changes that I make to the code as well. please feel free to fork it. In the <...
Malachi's user avatar
  • 28.6k
5 votes
Accepted

Focus next element on keypress

The input elements are all siblings of each other, so you can use $.next() to select the next one that appears after the event target. There is no need to name ...
200_success's user avatar
5 votes

Restrict HTML input field to decimal

@JoeWallis is on the right track, but his solution requires more discussion. If you do decide to use a single validation regex, then you should use the HTML5 ...
200_success's user avatar

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