I am in a situation here, i think its a simple one but i can't sort it out. I Have a HTML element where i should pass a json Object
code
var x = "<li id='tag_1'></li>"
var obj = {"name":"krishna","id":"krish1"}
when I convert this to html i want to get Like this
<li id="tag_1" data-options={obj}></li>
I tried $(x).data("options",{obj}),
tried to pass as a string when creating the html element,but did'nt work
Thanks
.datawill not createdata-optionsfor you. Take a look at the jQuery spec of what it actually does.{obj}is invalid syntax. You can simply use$(x).data('options', obj). It will, however, not be saved on the HTML tag but rather just in jQuery's memory. Example:$('body').data('foo', { foo: 'bar' }); $('body').data('foo');givesObject {foo: "bar"}.