Hugo Mota
Hugo Mota

Reputation: 11567

storing values in the markup for using in javascript (not xhtml compliant)

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 (:

Upvotes: 0

Views: 40

Answers (1)

Andr&#233; Laszlo
Andr&#233; Laszlo

Reputation: 15537

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.

Upvotes: 1

Related Questions