what is the meaning of jquery random attributes in html ? [expando attribute]

This is the jQuery expando attribute, it’s a bit random because it’s generated on page load, it’s "jQuery" + (new Date()).getTime() (to avoid possible naming conflicts) but you’ll notice the attribute is the same for all elements.

This is they key in $.cache for the element’s events and data…it’s stored this way for a few reasons, the main is to avoid circular references. The ID is actually $.uuid which is just an incrementing counter used for each element’s key in $.cache.

You can get the current attribute in jQuery 1.4+ with a simple alert($.expando), for an example of how it’s used, say you wanted the data for that #wmd-preview element, doing this:

$("#wmd-preview").data()

Is doing this:

$.cache[$("#wmd-preview")[0][$.expando]]

Also note that jQuery intentionally strips these out when you call .html() to get the content.

Leave a Comment