Rounding numbers with Javascript

The Javascript Math object has various mathematical functions and constants including .round() for rounding, ceil() for rounding numbers up and floor() for rounding numbers down.

Clear upload file input field with jQuery

The value of an HTML file input field cannot be changed or reset (without doing a full form reset) for security reasons. The other day I read Bogdan Gusiev’s post about how to clear an upload file input field by resetting the HTML of a containing div to its intial state using Javascript and thought I’d take it one step further by doing this in jQuery and adding a clear button next to any file input field on a web page.

Loop through selected elements with jQuery (Revised)

Earlier today I posted how to loop through elements in jQuery but as pointed out by Bloid at DZone it wasn’t a very good way of doing it. This post is a revision to that earlier post and thanks to Bloid for letting me know a much better (and more jQuery way) of doing this.

Get the milliseconds with Javascript and measure time

If you need to measure how long something takes with Javascript you can use the Date() object to get a start timestamp and then compare it later on using a second Date() object. Although I’m sure there are other benchmarking plugins etc available this can be a quick and easy way to benchmark something in Javascript.