Ala Ala - 1 year ago 146
Javascript Question

JS Exception : animate is not a function

I've an image inside a

, and the following Javascript code:

function animate_down(key1, key2)
cimage = document.getElementById('sslot_img' + key1);
var topval = cimage.offsetTop;
if (topval == -416) {
cimage.animate({ top: '0px' }, 5000);
else {
topval = topval - 32;
var toptxt = { 'top': topval.toString() };
cimage.animate(toptxt, 5000);

I've test it in Firebug, when the debugger reaches
function it's throwing :

cimage.animate is not a function

what am i missing?

Answer Source

getElementById is not a jQuery function, and will not yield a jQuery object. animate is only available on jQuery objects. You need to either wrap your cimage:

$(cimage).animate( ... )

or fetch it through jQuery rather than getElementById

var cimage = $('#sslog_img' + key1);

Note that if you go with the latter option, cimage will not have an offsetTop property, but rather, you'd have to use



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download