Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

what is the meaning of these jquery random attributes in html and how jquery use them

alt text

any ideas please ??

like image 995
Mahmoud Farahat Avatar asked Oct 13 '10 09:10

Mahmoud Farahat


1 Answers

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.

like image 120
Nick Craver Avatar answered Sep 20 '22 02:09

Nick Craver