Tuesday, January 24, 2012

The Trailing Comma Bomb

Well, they got me again.  Those pesky trailing commas in JSON objects. If you don't know what I'm talking about, then you probably haven't been doing JavaScript in IE7, because Firefox, Chrome, and IE8 and up all ignore them.

Monday, January 16, 2012

jQuery's .html() method, and the Undocumented Argument Type

By Dave Leeds

So the other day I was sending a JavaScript string into jQuery's .html() method, and I got this funky, funky little exception in Firefox:

Error: uncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMDocumentFragment.appendChild]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)"
And in Internet Explorer, the message was this:

Thursday, January 12, 2012

Nested Statements in jQuery

As we all know, jQuery's powerful selectors allow you to quickly create an object that contains multiple elements from the DOM, and manipulate all of them in a single line. (Noob stuff, I know, but hang with me, here...) For example:


We're saying, "Find all the divs, and generate something random to go inside them." Obviously, the content will only get inserted if one or more divs are on the page.

If you were to write that instruction without jQuery, you'd probably write it a little something like this:

// Translation of $("div").html(generateSomethingRandom());
var divs = findDivs(); // a fictitious method
for(var i = 0; i < divs.length; i++) {
 div.innerHTML = generateSomethingRandom();
But, in fact, that would be incorrect!
Profile Picture
Dave Leeds
My Hobbies:
  • Programming
  • Cartooning
  • Music Writing
Full Profile