I am building a script to create a table of content dynamically, I am setting the dataset attribute on each header and creating a li element with the name of this header, but I also need to insert a data attribute on my li item, this is not working
function createSummary() {
const summary = $('#summary')
for (let i = 0; i < headers.length; i++) {
let header = headers[i]
header.dataset.header = i
$('<li/>', {
text: header.innerText,
// HERE IS WHERER I NEED HELP
data: {'to': i},
}).appendTo(summary);
}
}
i also tried to put right before the appendTo }).data({'to': i}).appendTo(summary);