tags:

views:

69

answers:

2

I have a bunch of elements (divs) and they represent items. I can delete them by clicking a link and its done through ajax. I had the divs store the value in id however it appears that even though it does work the standard says id names must start with a letter. So i could start it with a letter and remove it when i use ajax or i can store the value another way.

What are ways i can store values in html? I don't think inputs are legal outside of forms but i am rethinking what are good ways to store values.

+2  A: 

You can store it as text inside the div if you like. You also can use inputs, just add the form tag around everything. Just because it's a form doesn't mean it has to "submit". Inputs or textboxes would probably be the best way to store them actually.

Joel Etherton
Maybe i should accept this. This is what i am using.
acidzombie24
instead of a div i used textarea and jquert .val()
acidzombie24
+4  A: 

Best way is to use the new HTML 5 spec to store data in the data-[name] in the div elements

ie

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

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

div[data-yourField=""]
Jason Jong
Jason, you have a link to this portion of the spec?
Mike Sherov
Hi Mike, see this URL http://dev.w3.org/html5/html4-differences/Half way down the doc you'll see "There are also several new global attributes:" :: The data-* collection of author-defined attributes. Authors can define any attribute they want as long as they prefix it with data- to avoid clashes with future versions of HTML. The only requirement on these attributes is that they are not used for user agent extensions. Also, John Resig talks about them in his blog: http://ejohn.org/blog/html-5-data-attributes/
Jason Jong
Here is the proper link: http://dev.w3.org/html5/spec/Overview.html#attr-data
Jason Jong