jQuery.data vs jQuery.fn.data performance

July 9th, 2011

jQuery.data( element,key,value )
“Store arbitrary data associated with the specified element. Returns the value that was set”

.data( key,value )
“Store arbitrary data associated with the matched elements.”

Performance difference: on this jsPerf test the last is about 84% slower.

So instead of:
$('#element').data('type', 'critical')
prefer:
jQuery.data('#element', 'type', 'critical')

(tested on Google Chrome 12.0.742 browser)