Javascript Hoisting
When using JavaScript, you declare a variable using the var keyword. var myvariable = “a value”; These variables are globally accessible unless they are defined within a function. Javascript performs an operation known as “hoisting” when it compiles which draws all the declarations to the top of the page. Here is a piece of code: [...]
Viewing events attached to elements via JavaScript
If like myself, you often attach functions to elements using jQuery, for example: $(‘.btnName’).live(‘click’, function() { //do something }); There is a nice little browser extension that will show all the elements on the page with a little bubble outlining the attached events/functions. It is written by Allan Jardine, and you can get it from [...]
JQuery – bind event to non existant element
We all have to bind events to elements: $(‘#link).click(function(){ do some stuff }); But, what if that element doesn’t exist yet? Well, you can use the “live” handler: $(‘#link’).live(‘click’, function(){ do some stuff }); This will carry the event handler on and will match any future element that matches the selector. More information [...]
Sorting a SELECT with JQuery
Just a simple function to sort an already populated list. Obviously it would be easier to sort before populating, but there are the odd occasion where this is more complicated than you thought. Requirements : JQuery var selectOptions = $(“#selectId option”); Then, we just run the sort command on the options array – and this [...]
I wrote one of the first social networking sites
Its not a claim to fame, or a preempt to a court case to a ‘big hitter’, but back in the year 2000, when I was a fledgling junior programmer, I wrote an ASP web site based around a bunch of ‘buddies’. You could add people to your list, message them, upload a picture (just [...]
Javascript Language Translation
On a project I am working on, I need to enable language translation. Thinking about it, turned into something quite complicated. But then I found the Google Language API which allows developers to hook into the Google Languages services. So, I start a page – enabling UTF-8 character sets: < meta content=”text/html; charset=UTF-8″ http-equiv=”content-type”> And [...]