Data Attribute is declared as a part of your HTML element and will act as a variable that holds string type data.

This is a sample of how to use data attribute.

 

This is the example of getting the data-info value using JQuery

alert($(‘#my-html-element’).data(‘info’));
//or
alert($(‘#my-html-element’).attr(‘data-info’));

Many JQuery and JavaScript library are using data attribute to act as their parameters.

Share on Google+Tweet about this on TwitterShare on FacebookShare on TumblrShare on StumbleUponPin on PinterestShare on LinkedInDigg thisShare on RedditEmail this to someone