html5 - jQuery append new key value pair to existing data attribute -


is possible, div data attribute is:

data-obj="{"__type":"galleryimgmodel","galleryimageid":49,"galleryid":0,"personid":264}" 

and jquery tried based on docs (ive defined item correctly!)

item.data('obj',{"morethanoneimage" : morethanoneimage}); 

help great thanks

you need convert data attribute string object first, add value(s). try like:

$('#my-element').data($.extend({'new-key':'new-value'},     json.parse($('#my-element').data())); 

something should trick.


Comments