I have found a solution to my problem and thought I'd share it in case
I'm not the only one in this situation.

First thing I did was to switch to an alternative way of storing
metadata (using the data attribute) since using the class attribute
was more dificult to parse / update when there were also CSS classes
set for the same element. So my HTML looks something like this:

<li id="item_1" data="{name:'first item', subitems_count:3}"><a
href="#">Update</a></li>
<li id="item_2" data="{name:'second item', subitems_count:7}"><a
href="#">Update</a></li>

When someone clicks a link the metadata is loaded into an object and
any modifications are made on the object (in my case I make an ajax
call to the server, get the new subitems_count and update the object).

Now I'm using a JSON stringifier (thanks to Thomas Frank for this one,
http://www.thomasfrank.se/json_stringify_revisited.html) to transform
the object back into a JSON string.

After that I'm using jQuery's attr(key, value) to reset the data
attribute to the new string.

Pretty easy but my noobiness prevented me from figuring it out
earlier.

Have a nice day!

Reply via email to