Category Archives: JavaScript

Internet Explorer Array.sort Unreliable

What would you expect to be the result of executing the following code? // Create a medium size array, at least 100 items var obj = []; for(var j=0, k=150; j<k; j++) { // the value here doesn't matter. obj.push('ABCD'+j); }   // Sort the array alphabetically. obj.sort(function(m,p){ m=(''+m).toLowerCase(); p=(''+p).toLowerCase();   [...]
Posted in JavaScript | Tagged , | 9 Comments

Trash that “Back to Top” Link

It would seem that perfection is attained not when no more can be added, but when no more can be removed. - Antoine de Saint Exupéry While most would argue that the principles espoused in the above quote might also be applied to the quote itself, it would serve us better to consider how we can attempt [...]
Also posted in Interface Design | Tagged , | 1 Comment

Quick Performance Tip: jQuery and addClass

Abstractions are helpful and dangerous. But the more we know about a library’s internals, the less danger we’ll be in later. Here’s an issue I ran into where I had assumed that jQuery would be optimized for this case, but it wasn’t. I’ll go over my bad assumption and how to workaround [...]
Posted in JavaScript | Tagged , | 2 Comments

Performance Caveat with jQuery Selectors and Live Events

Prerequisite: Knowledge/Experience with jQuery Live Events (new in jQuery 1.3), and the concept of Event Delegation. When developing on the front end, it’s easy to prioritize correctness over performance. Performance is the step child that gets lost while you’re pulling your hair out worrying about cross browser compatibility. It’s very important to regularly benchmark [...]
Posted in JavaScript | Tagged , | 11 Comments

Scare Your Visitors with this JavaScript Gravatar Plugin

Here's a use case. An unregistered visitor visits your blog, and decides that your content is so good that it merits a comment! Congratulations, you've fooled them! But since they're leaving a comment, why not show them a preview of their gravatar?
Also posted in Projects | Tagged , | 5 Comments

DOMContentLoaded Inconsistencies (in Browsers and JavaScript Libraries)

We all know the problem, but we may not all call it the same thing: DOMContentLoaded. Every popular JavaScript library has its own name for the DOMContentLoaded event, and they're all implemented differently. This, of course, partly due to the fact that web browsers are also inconsistent in their implementations. Here's a run-down of those inconsistencies.
Also posted in Web Browsers | Tagged | 1 Comment

Emulating onhashchange without setInterval

There is one limitation that all of the major JavaScript browser history management plugins have to hack around: How to tell when there is a change to the location.hash? Sure, you can tell when you’re modifying the hash yourself, but what if the user hits the back/forward button? YUI’s History component and Really Simple [...]
Posted in JavaScript | Tagged , , | 10 Comments

Selecting XML Nodes with JavaScript (Peril of getElementsByTagName)

Parsing XML in the browser can be a tricky beast. There are many different wrong ways to do it, which can leave you cold and naked in a snowstorm if you're not careful. So, let's put on the metaphorical electric one-sie of standards based code and let the power of Edison heat our JavaScript code like the innards of a tauntaun.
Posted in JavaScript | Tagged , , | 4 Comments