I'm trying to add multiple classes from JSON file to a HTML element that I created with Jquery in the same function. Problem is none of the classes are going trough. Some of the JSON data sections(items) have more than one class, they are set in an array. HTML part is created and it gets the dat.location but its not getting any of the classes. I think there is something wrong in how I'm inserting the classes but not sure what.
How can I insert the classes to txtp variable in the function?
function CreateContent(data) {
for (var i = 0; i < data.length; i++) {
var dat = data[i];
var txtp = $('<p class="column" href="#">' + dat.location + '</p>');
$(txtp).addClass(dat.items1);
$(txtp).addClass(dat.items2);
$(txtp).addClass(dat.items3);
$(".positionInHtml").append(txtp);
}
}
This is what the JSON data file contains, thou I simplified/changed the variable names for this question.
{
"Places": [
{
"location": "Name1",
"items1": [ "1A" ],
"items2": [ "1B","11B" ],
"items3": [ "1C" ]
},
{
"location": "Name2",
"items1": [ "2A" ],
"items2": [ "2B" ],
"items3": [ "2C","22C" ]
}
}
datstructure and preferably a working snippet demonstrating your issue?$(txtp)object.