So I want to create a block of elements taking classes and attributes from an object.
I use a function to create the object
function profile(name, img, health, strength) {
return {
name: name,
img: img
}
};
Then I use jQuery to create a div and use the object to provide a class
function pushProfile(profile) {
$('<div />', {
"class": profile.name,
"class": 'profile',
text: 'test'
}).appendTo('.profile-class');
};
So far it seems everything is working. My question is can I add nested elements to the new div inside the same function? Something like this?
function pushProfile(profile) {
$('<div />', {
"class": profile.name,
"class": 'profile',
text: 'test'
}).appendTo('.profile-class');
$('.' + profile.name).prepend('<img src=' + '"' + profile.img + '" />');
};
I'm fairly sure what I wrote for adding the img is wrong but I can't seem to find any documentation on someone doing anything similar to this so I may just be going about this wrong. If anyone has any suggestions on a different method I am absolutely open to those.
Thanks!