Ticket #4590 (closed feature: wontfix)
Querying element data (jQuery.data) as attributes
|Reported by:||james_padolsey||Owned by:|
Not sure if this is an "enhancement" or a "feature".
jQuery's attribute selectors ('[prop=val]') currently only supports DOM properties of the element in question, heck, it even let's you query the innerHTML property.
I thought it would make a nice improvement to make it also support querying of element data (added via $(elem).data()). So, when you add a new data key, it's immediately available to query through the familiar attribute selector.
/* Add data */ $(elem).data('ABC', '123');
/* Query within selector */ $('*[ABC=123]');
You can see the code used to implement it at the above URL.
DOM properties will always take precedence over data keys. So if you search for $('a[href= ftp://]') then the DOM property will be checked if it exists, even if there is a data key by the same name ("href").
Obviously this only works effectively with strings, but the truthy'ness of a data value can also be checked, for example:
/* Add data: */ $(elem).data('active', true);
/* Find active elems: */ $('div[active]');