views:

191

answers:

2

I'm looking at using the jQuery MetaData Plugin. Looks very interesting but...

<li class="someclass {some: 'data'} anotherclass">...</li>

<script>alert($('li.someclass').metadata().some);</script>

does this code validate?

http://docs.jquery.com/Plugins/Metadata/metadata#options

+4  A: 

Well according to the XHTML Strict DTD (and, I think, all the other relevant DTDs), the "class" attribute is CDATA, so that means just about anything goes in the value.

Pointy
A: 

If you are using jQuery, just use the .data() method!

$(elem).data(key, value);
//e.g. store a string
$('#someID').data('secret','my voice is my password, verify me!');
//or store some JSON
$('#otherID').data('stuff', JSONData);
scunliffe
Im tired of hearing this suggestion!
codeninja
@codeninja - sorry about that. I was under the impression that this was the desired outcome. Storing JSON data on an element that doesn't wreck your valid (X)HTML. Using the class attribute can work, but it seems like a kludgy abuse of the attribute IMHO.
scunliffe
its cool. you didnt really answer my question.
codeninja
@codeninja - ah, it wasn't clear that you were looking for a solution to store the data *only* in the HTML to be pulled out later. (I found your other question on the same topic). class should work then unless you want to use the HTML5 data- attributes (knowing they will break XHTML strict in older browsers).
scunliffe
thanks much for the info =]
codeninja