Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery is adding a strange attribute to nodes

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?

like image 988
Charles Anderson Avatar asked Jul 23 '10 09:07

Charles Anderson


1 Answers

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.

like image 99
James Avatar answered Oct 13 '22 03:10

James