views:

47

answers:

1

I'm using IE8 and jQuery 1.4.2. My web page is no longer rendering correctly, and a quick look in the debugger at the HTML shows that every element now has a new attribute called "jQuery1279875396122", whose value is a small integer, apparently unique to each node.

Looking at the jQuery source I can see that the long number comes from (new Date).getTime(), but that's the limit of my understanding without a lot more research.

I don't know if this is related to my rendering problem, but I've never noticed it before, in IE8 or any other browser. Can someone explain what these attributes are?

+5  A: 

jQuery uses these "expando" properties to keep track of data associated with elements. jQuery uses its data API for event handling plus any general data that you may want bound to an element (using $.data).

The property (jQuery1279875396122) will have a value associated with a position in jQuery.cache.

The reason jQuery doesn't save data directly to the element (as regular properties) is to avoid memory leaks and just to generally be a little less obtrusive.


Just as an example, when you bind an event handler to an element, like so:

jQuery('div').click(doSomething);

The doSomething function will be stored in jQuery.cache and, on a rudimentary level, its position (or rather, the position of the object that references it) will be assigned to the element's jQuery1279875396122 property. jQuery will still use the browser's native API to bind to the element's event but when it's fired jQuery will lookup (in jQuery.cache) and call the correct handlers.

EDIT: Just to be clear, these properties are not a cause for concern. You should expect to see them on all elements that have any data bound via jQuery (including event handlers). I would be very surprised if this was the cause of your rendering problem.

J-P
Interesting. But I have never seen these attributes before, and I still can't see them in Firefox/Firebug. Also, every node has one, not just the ones we've stored data in.
Charles Anderson
@Charles Anderson, You may not have intentionally stored the data in these nodes. jQuery uses its data API for internal tasks. Also, the expando property is only visible as an attribute in IE (AFAIK). FF and other browsers treat it as a regular DOM property and so it won't appear in the actual HTML.
J-P
Just thought I'd add my vote of confidence to the fact these will make no difference to rendering at all.
Chris
I think you're right that this isn't causing my rendering issue. I normally debug in Firebug because it's much nicer than IE's debugger. Therefore I don't spend much time looking at IE's view of the HTML. Now that I've got an IE8-specific problem I've had to go in there a lot, and I've noticed these expando attributes for the first time, hence the coincidence. (Incidentally, sometimes IE8 doesn't show them.)Thanks for the full explanation of what they are though.
Charles Anderson