jQuery .data usage

By Anil Kumar Jan 20, 2012
Why and how to use .data in JQuery.
jQuery .data()  usage :

I use .data for storing values instead of accessing DOM elements. I realized and found a better and faster way of it. In fact I have been using $('#myElementID').data(myKey,myValue); for a while now. 

Check out these cases.  

The other way for the same is as -

$.data('#myElementID', key, value );

case 1 : 


It creates a jQuery object and then do the data parsing. It creates an overhead.

case 2 :

$.data('#myElementID', key, value );

This one is faster than first. As it does not go for object creation.

Please comment.

Anil Kumar
Anil Kumar

Anil Kumar is a passionate web developer, previous business owner, social executive, and a father. He has 9+ years of exposure in diverse technologies at variant roles. Anil is much inspired with Mr. Mahesh of c-sharpCor... Read more

Personal Blog: http://CodePattern.net