Entries filed under 'Javascript'
Odd jQuery gotcha: IE and .html()
Filed under Javascript on 30.04.08
Here’s an odd one.
If you use jQuery’s .html() method to find a string of HTML, beware if that HTML contains any elements that have events registered—you might get a little more than you bargained for.
Here’s a simple test case:
<div>
<button id="test">What is the magic number?</button>
</div>
And the JavaScript to attach an event to the button that alerts the HTML contained in its parent element (the div):
Read the full entry... | Comment
Facebook and the new Google Analytics ga.js tracking
Filed under Javascript on 25.02.08
You’ve got to question the decision by the Google Analytics team to recommend the use of document.write in the updated version of their tracking script. Aside from breaking any XHTML pages served correctly, it also doesn’t work in IFRAMEd Facebook applications—I guess they don’t like document.write either, most likely for security reasons.
Read the full entry... | Comment [6]
jQuery tablesorter secondary sorting problem
Filed under Javascript on 11.12.07
While switching a table sort script over to the excellent new jQuery Tablesorter 2.0, I came across an implementation that, to me, didn’t seem right.
In the configuration options, you can set a forceSort column, which—according to the documentation—will “add an additional forced sort that will be appended to the dynamic selections by the user”. What it actually seems to do, though, is apply the forced columns before the one you clicked on, meaning that you can’t actually sort by anything apart from the forceSort column(s).
Read the full entry... | Comment
Easier autopopulating textboxes with JavaScript
Filed under Javascript, Accessibility on 18.10.07
Roger Johannson just posted a rather lengthy script over at 456 Berea Street that is intended to help the accessibility-conscious developer combat their designer’s label-less form design. It struck me as a little silly to repeat the label as an unnecessary title attribute, so I wondered how easy it would be to use the existing label instead of futzing with the input value. As it turns out, it’s very easy—here’s how to do it.
Read the full entry... | Comment [4]
A thousands renderer for the Ext Grid control
Filed under Javascript on 17.09.07
I needed to format large numbers by adding thousand separators in my Ext.js powered grid—and, as I couldn’t find one anywhere else, I wrote my own quick implementation. Here’s what I came up with:
function add_thousands_separator(input) {var s = input.toString(), l = s.length, o = '';while (l > 3) {var c = s.substr(l - 3, 3);o = ',' + c + o;s = s.replace(c, '');l -= 3;}o = s + o;return o;}- Download this code: /code/renderer.txt
Hopefully someone else might find this useful too.
Read the full entry... | Comment
long is a reserved keyword in Safari
Filed under Javascript on 25.05.07
This is more a note to myself than anything else, but it might help someone pulling their hair out over this particular bug.
Apparently, long is a reserved keyword in the Safari browser (I’m using 2.0.4, but it’s fixed in the WebKit nightlies), so be careful if you’re using it as a variable name—I’ve been working with the Multimap API today, so lat and long seemed like perfectly natural properties of my hotel objects until Safari choked.
Read the full entry... | Comment [1]
jQuery == 'undefined'
Filed under Javascript, Internet on 6.05.07
UPDATED 05/08: Apparently they were subject to a DDOS attack and then booted by their host – you can contribute to their server fund on the site.
The jQuery JavaScript library website seems to be dead this morning, which means the DNS that allows them to serve their latest build from Amazon’s S3 service is also kaput. Hope nobody’s using the code.jquery.com URL on their live site, as jQuery have just broken all your functionality…
Read the full entry... | Comment [2]
Joe Hewitt on Firebug 1.0
Filed under Technology, Javascript on 30.01.07
Finally got around to watching the Yahoo! video of Joe Hewitt demonstrating some of the ‘power-user’ features of Firebug – pure awesomeness.
Read the full entry... | Comment
jQuery The Magazine
Filed under Javascript on 27.09.06
There is now a PDF Visual jQuery Magazine available – I wonder if we’ll see any other communities going this route to publicise themselves?
Update 29/09: Perhaps I should become a prophet... ;)
Read the full entry... | Comment
Equalising box baselines with Javascript
Filed under Javascript on 22.08.06
A while ago I wrote about creating equal height boxes using Javascript, and occasionally I find myself referring back to that article when I need the technique for a project.
Recently I added it to a layout only to find it didn’t have quite the effect I intended. One of the boxes had a top-margin applied, so equalising the box heights meant that their bottoms were still out of line – I needed a means of lining up the baseline of the boxes.