I think you want to do the same thing in pure JS form. For this please see the code below -
for(var prop in ss) { // iterates over each property of ss object
div.setAttribute(prop, ss[prop]); // sets an attribute on the div element, first parameter is attr name and second one is its value
}
However, only problem will be the CSS property which is an object. Rest other will be applied as they are using jQuery.
UPDATE: I've found a workaround for this. See below -
for(var prop in ss) {
if(typeof ss[prop] !== 'object') { // confirms property is NOT an object
div.setAttribute(prop, ss[prop]);
}
else { // if the property is object
div.setAttribute(prop, '');
var val = '';
for(var p in ss[prop]) { // iterate through the properties of the object
val += p+":"+ss[prop][p]+';'; // concatenate them all in one
}
div.setAttribute(prop, val); // and finally set the attribute
}
}
Here is the working example (using Pure JS).
Full Snippet:
var ss = {
id: "foo",
class: "attack",
dataa: "hhh",
style: {
"color": "red",
"font-size": "50px"
}
};
var div = document.createElement('div');
div.innerHTML = 'dsdf';
for (var prop in ss) {
if (typeof ss[prop] !== 'object') {
div.setAttribute(prop, ss[prop]);
} else {
div.setAttribute(prop, '');
var val = '';
for (var p in ss[prop]) {
val += p + ":" + ss[prop][p] + ';';
}
div.setAttribute(prop, val);
}
}
document.body.appendChild(div);