Store values ​​in html

I have a bunch of elements (div) and they represent elements. I can remove them by clicking the link and executing it through ajax. I had divs store the value in id, however it seems that although it works, the standard says that identifier names should start with a letter. Therefore, I can start it with a letter and delete it when I use ajax, or I can save the value in another way.

How can I store values ​​in html? I don't think the input is legal outside the forms, but I rethink what is a good way to store values.

+4
source share
2 answers

The best way is to use the new HTML 5 specifier to store data in data- [name] in div elements

t

<div data-yourfield="value"> Text </div> 

Then, using jQuery, find the divs with the selector (link http://api.jquery.com/category/selectors/ )

 div[data-yourField=""] 
+5
source

You can save it as text inside a div if you want. You can also use input, just add a form tag around everything. Just because this form does not mean that it must "obey." Entries or text fields are likely to be the best way to actually store them.

+2
source

Source: https://habr.com/ru/post/1299913/


All Articles