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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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...
this link is awesome. there's a lot of useful compliant techniques! thank you very much!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.