Monday, October 19, 2009

JQuery slideDown() is Annoying

I recently ran into a very odd feature of the JQuery slideDown() function. As it turns out, whenever you call that function on a DOM element the final result of the function is to set the css 'display' property of the element to 'block'. Which is just plain stupid. That means that if I call slideDown() on a <td> element then it will finish with a display property of 'block' instead of it's appropriate default display property. This wrecked havock on a website that I was building because I thought that show() and slideDown() were interchangible; they are not.

I found somebody that had the same problem: here. But they proved to be little help; I personally believe that they deal with it the hard way.

The solution to this problem was easy but a hack really. The slideDown() function has a callback function; a back door for fixing up its behaviors if you will. The function prototype is:

slideDown(speed, [callback])

That means that I merely defined the following function:

function clear_display() {
$(this).css("display","");
}

And then I proceed to call the call the function like so:

$(".some_class_on_a_td").slideDown("normal", clear_display);

And that is all, problem solved, kinda. I have posted to jQuery and asked them to explain why it behaves in this manner. I'll edit this post if I get some more information but for now I hope this helps somebody.

0 comments: