Create a simple 10 second countdown

JavaScript has built in to it a function called setInterval, which takes two arguments – a function, callback and an integer, timeout. When called, setInterval will call the function you give it every timeout milliseconds. For example, if you wanted to make an alert window every 500 milliseconds, you could do something like this. However, … Read more

jQuery sort elements using data id

I have an HTML structure as follows: I would like to sort them as: I am using the following function: It is not working as expected. It is working well for the first run but after adding new element or changing the data-sid attributes it no longer works. Demo: http://jsfiddle.net/f5mC9/1/ Not working?

Javascript swap array elements

You only need one temporary variable. Edit hijacking top answer 10 years later with a lot of ES6 adoption under our belts: Given the array arr = [1,2,3,4], you can swap values in one line now like so: This would produce the array [2,1,3,4]. This is destructuring assignment.

Keep getting a “Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup” when attempting to google plus login on my web app

I’m trying to implement Google plus sign up on my web app and I followed the google docs to set up the sign up however when I attempt a signup after accepting permissions and using the access token returned to me any api restcall I make returns the Daily Limit for Unauthenticated Use Exceeded. Continued … Read more

Javascript: difference between a statement and an expression?

Are all statements also expressions? “Wherever JavaScript expects a statement, you can also write an expression. Such a statement is called an expression statement. The reverse does not hold: you cannot write a statement where JavaScript expects an expression. For example, an if statement cannot become the argument of a function.” This is comes from … Read more

Simple pagination in javascript

I’ll address any questions you have… but here is an improved pattern you should follow to reduce code duplication. As a sidenote though, you should consider not doing pagination on client-side. Since if you have a huge dataset, it would mean you need to download all the data before your page loads. Better to implement … Read more