0

sometimes i store values in the element's atributes for using in javascript.

ex: <div class="open_popup" target="first_popup">click here</div>.

also, some javascript plugins that i use put elements in the page with the atribute generated="true".

it is a very useful technique for me but it is not compliant with the strict versions of xhtml.

what problems should it cause?
should i worry about that?
if i should, what's the solution?

thanks (:

Hugo Mota
  • 11,200
  • 9
  • 42
  • 60

1 Answers1

1

I would use the jQuery.data method:

// attach ('foo', 52) to the key/value store for the document.body element
jQuery.data($('#id_of_your_element'), 'foo', 52);

The problems with your method, at least the way I see it, is that it is not valid xhtml. And why would that matter? Basically, you don't know exactly how a browser would handle your invalid attributes - it might just strip them off the dom node or something else completely.

André Laszlo
  • 15,169
  • 3
  • 63
  • 81
  • yes. that is exactly the problem. your solution is very nice! but it requires me to select each element and atatch data to it. i wanted to create the functions with jquery and simply use the markup to control the behavior... – Hugo Mota Jun 25 '11 at 18:35
  • this link is awesome. there's a lot of useful compliant techniques! thank you very much! – Hugo Mota Jun 25 '11 at 19:07