Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save data in html tag attribute

How save some data as html tag atribute? For example, given data asd/45.33/blah, I need save this data in html and after using jquery get this data so:

 $("#my_tag").attr("special_attribute");

its possible?

like image 924
Oto Shavadze Avatar asked Feb 18 '23 01:02

Oto Shavadze


1 Answers

Using custom attributes makes your document invalid, you can use HTML5 data-* attributes and for getting/setting values using jQuery, you can use data method, for example if you have a data attribute called data-special you can get the value of it in this way:

var value = $("#my_tag").data("special");

and set/change the value in this way:

$("#my_tag").data("special", "value");

http://api.jquery.com/data/

like image 74
undefined Avatar answered Feb 21 '23 03:02

undefined