jQuery Is Awesome. Yet Again.

I know that this probably isn’t news to any of you who care about such things and follow the world of web development even a little… it’s not even news to me, really – I’ve been an advocate of this particular programming library for a while now. But today in particular, I just felt so enamoured by the elegance of the jQuery Javascript Framework that I had to tell you about it.

This line of code:

$('.alpha').not(':has(.beta:visible)').hide();

Hides all elements with the class “alpha” which contain no visible elements with the class “beta” (i.e. if it contains any visible elements of class “beta”, the “alpha” is not hidden).

And it’s just beautiful. Just to compare how elegant it is to something else, here’s the equivalent code in Prototype, another popular Javascript framework, which in itself still shortens the amount of code that this would take in plain-old vanilla Javascript:

$$('.alpha').each(function(element){
var has_visible_beta = false;

element.childElements().each(function(inner_element){
if (
inner_element.hasClassName('beta') && inner_element.visible()) has_visible_beta = true;
});
if (
has_visible_beta) element.hide();
});

(okay, that Prototype code could probably be a hair simpler, but you get my point)

Wow.

The Most Terrifying Thing A Web Developer Will Ever See

Want to see something quite terrifying: DHTML Lemmings. I kid you not – this is scary shit, particularly when you realise that it’s all being done client-side, using script, over the web: no Flash, no Applets, no ActiveX <spits> – just pure unadulterated CSS and JavaScript. I got scared.

Royal Welsh Show

I’m writing this from the (badly-protected: just had to go to a page with a particularly funky JavaScript to break out of their front-end browser) BBC Wales bus at the Royal Welsh Show, where Alex and I are working on behalf of SmartData.

Suppose I’d better get back to work and let these kiddies have the ‘net connection back…