DavidTonarini DavidTonarini - 8 months ago 43
jQuery Question

Jquery, cannot access css properties of dynamically generated element

I am using jQuery to append elements to a div, and all works fine.

var new_div = $('<div>My stuff</div>');

However, I'd like the div to appear by fading in, instead of abruptly.

I notice though that I get an error when I try to access graphic properties on my dynamically generated element. So this, for example fails:


The console reports the following error:

TypeError: jQuery.curCSS is not a function

Do I understand this correctly, that this fails because current css properties are not defined for the dynamically generated element? Or what else can be goingg wrong?

Important edit
Additional checking and working on this pointed out to a complete misunderstanding from my part. This has nothing to do with the fact that the element was dynamically generated. I got the same thing by calling fadeIn() on whatever element.
I sincerely apologize!
I still didn't get, though, why this happens


It does seem to be a compatibility question, although I wasn't able to figure out exactly why and how to fix it. Adding this code fixes the problem though:

jQuery.curCSS = function(element, prop, val) {
  return jQuery(element).css(prop, val);