in jquery if i use $("#my_button").data('my-value', { onClick: function () { my_obj_function(); } });
and in another function i do this
my-value.onClick.call() it works.
but if i try to set the data attrib in html it not working.
i did this in html
<a href='#' data-my-value='{"onClick":"function () { my_obj_function(); }"}'>Click me</a>
while calling my-value.onClick.call() i'm getting
uncaught typeerror : object function() has no method call
what am i doing wrong?
<a ... data-my-value="..." ...>is equivalent to$(...).data('myValue')..data()method can retrieve html5data-attributes, but it can't set them.data-attributes are strings, but.data()can store other types including objects.$.cacheis used by jQuery to handledata(), but I thought it was worth mentioning the slight disconnect between the data key and the attribute Rifky was using.