Archive for the 'JavaScript' Category

Use jQuery to find the first parent element

Saturday, December 20th, 2008

I have run across this problem a few times lately and I thought I would write a post here as a way of remembering how to do it.

So you are doing some DOM Scripting and you want to find the first parent element that has a particular class. I have been using jQuery a lot lately and I initially thought this would be easy:

$('#test').parents('.parent-element');

However, as you notice with the example below you get all the parent elements with the specified class. So all we need to do now is filter out just the first element, like so:

$('#test').parents('.parent-element').filter(':first');

Done and done, see some example code to show it in action: Use jQuery to find the first parent element

I hope someone else finds this useful.

Technorati Tags: , , ,

Animated loading gif images

Sunday, August 26th, 2007

After needed an animated loading .gif image for a recent Ajax application I did some quick Google searching and came across a fantastic site: http://www.ajaxload.info/

Ajaxload allows you to generate your own animated Ajax loading images with a few simple click. Starting from a number of animation templates you can then choose a background and foreground colour for your new loading .gif. After 30 seconds of playing around, see some of my examples below:

Ajax loader

Ajax loader

Ajax loader

Fantastic, yet simple. This is the way all websites you should be, well done Ajaxload.

Technorati Tags: , , , ,