addClass, removeClass and hasClass without jQuery

Class manipulation methods in jQuery are really handy, but when you need just them and nothing else out of jQuery, then using entire library seems like a little bit mistake. Using own versions of addClass, removeClass and hasClass sounds like a better idea and for this reason I have wrote following article, where you’ll find an example implementation of these methods.

Read More “addClass, removeClass and hasClass without jQuery”

Dropdown must use both onChange and onKeyPress events

Bear in mind that when writing JavaScript / jQuery code for handling user changes made to dropdown boxes, you must program your website reaction not only to onChange but also to onKeyPress events. Why? There is a rare situation, where user selects value by clicking dropdown and then using keyboard’s cursor up or cursor down keys. onKeyPress event will be fired in this situation instead of onChange event. And desired effect won’t work, if you put it only to onChange event handler.

Read More “Dropdown must use both onChange and onKeyPress events”

Human population counter

I’ve found a simple and cool JavaScript counter that is able to count current human population and it’s increase every second.

It:

  • takes current date and time,
  • calculates its different toward July 1, 1995 at 00:00:00 (when human population was 5 733 687 096)
  • multiply known “human population increase” factor by the number of seconds that passed since then till now

In this particular (very old — year 1995) example result is printed into form’s text box. With a simple modifications you can have this turned into a actual JavaScript function to return result.

Read More “Human population counter”