I'm having an issue getting jquery objects to render as html.
In the code below, the tickBox gets rendered as [object Object] and not as html whereas all the rest is rendered correctly.
I know I could just add it as a string but that's not the goal here.
Why does the tickBox not render as html?
const legendData = ['hello world', 'welcome back', 'hotel california', 'never leave'];
const tickBox = $('<div/>', {
class: 'tickBox',
html: $('<div/>', {
class: 'ticked'
})
});
const legendContent = legendData.map(item => {
return $('<li/>', {
dataId: `${item.split(' ')[0]}`,
html: `${tickBox} ${item}`
/* I know I could do this */
//html: `<div class="tickBox"><div class="ticked"></div></div> ${item}`
});
});
$('<div/>', {
id: 'chartLegend',
class: 'legend',
title: 'Chart legend',
html: '<p id="chartLegendHeader">Legend</p>'
}).appendTo(`#chartContainer`);
$('<ul/>', {
class: 'legend',
html: legendContent
}).appendTo('#chartLegend');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="chartContainer"></div>