From jQuery1.4.3, The HTML5data-attribute will be automatically referenced to the jQuery data object. That is to say, although data-* is an element in html5, if jquery1.4.3 and above are used. it can still be used on non-HTML5 pages or browsers. data (obj) method to Operate & quot; data-* & quot; data. after reading the HTML5 detailed specifications, you will find that the usage of this custom data attribute is very simple, that is, you can add any attribute starting with "data-" to the HTML Tag, these attribute pages are not displayed. They do not affect the layout and style of your pages, but are readable and writable.
This method has been built in jquery. by $ ('# content '). data ('LIST'); to obtain data. this method appears after jQuery1.4.3. It returns the corresponding data attribute.
Use of jquery to operate HTML5 data -*
Script
$ (Function (){
// Read the value of data -*
$ ("Li"). each (function (v ){
Console. log ($ (this). data ('name '));
});
// Set the value of data -*
$ ("Li"). eq (0). data ('name', 'bryant ');
$ ("Li"). each (function (v ){
Console. log ($ (this). data ('name '));
});
// Delete the value of data-*. removeAttr is used here. The removeData test does not work.
$ ("Li"). eq (0). removeAttr ('data-name ');
$ ("Li"). each (function (v ){
Console. log ($ (this). data ('name '));
});
})
Script