Ok, so the final solution, with combination of something I found on the web plus @Vega and @adeneo answers, here we go...
Using the following jQuery method allows me to get everything by calling blank attr():
(function($) {
var _old = $.fn.attr;
$.fn.attr = function() {
if (this[0] && arguments.length === 0) {
var map = {};
var i = this[0].attributes.length;
while (i--) {
map[this[0].attributes[i].name.toLowerCase()] = this[0].attributes[i].value;
}
return map;
} else {
return _old.apply(this, arguments);
}
}
}(jQuery));
I can fetch all the attributes like this:
var data = $(document.getElementById(id)).attr();
With that, I am keeping my element attributes EXACTLY as they way it was before (with HTML5 adjustment):
<div id="helloworld"
data-call="chart"
data-width="350"
data-height="200"
data-stacked="true"
data-value="[[4, 8, 1, 88, 21],[45, 2, 67, 11, 9],[33, 4, 63, 4, 1]]"
data-label="['test1', 'test2', 'test3', 'test4', 'test5']"/>
I then use JSON.parse() to deal with the data-value, and then use @adeneo's method to handler the string array.
data.value = JSON.parse(data.value);
data.label = data.label.split(',').map(function(val) { return val.trim().replace(/(\'|\[|\])/g,''); });
For my own other js code's purposes, I just trim off data- from the key and now everything is kosher!!
for (key in data) {
var newKey = key.replace("data-","");
if (newKey != key) {
data[newKey] = data[key];
delete data[key];
}
}
Now I can pass the data to my existing function!!!! :)
How I was calling my function before:
var data = {
id: 'helloworld',
width: 350,
height: 200,
value: [
[4, 8, 1, 88, 21],
[45, 2, 67, 11, 9],
[33, 4, 63, 4, 1]
],
stacked: true,
label: ["test1", "test2", "test3", "test4", "test5"]
};
chart(data);
Now I could use jQuery, find all element with certain class name, then just parse the attributes to trigger the call. :)