I'm curious about adding data content inside an array to innerHTML using the forEach method.
For some reason, I can't get it to show up. Is it even possible? I'm dealing with dynamic data, so I need to loop through it and display it using innerHTML.
const showPosts = (data, value) => {
const btnDiscover = document.querySelector('[data-show="discover"]');
const slides = data.add_post_slides;
const Posts = () => {
return slides.length > 0 &&
slides
.map((el) => {
return <h2>123</h2>;
})
.join('');
};
// console.log(Posts());
btnDiscover.addEventListener('click', (e) => {
e.preventDefault();
body.classList.add('toggle-legend', 'no-scroll');
console.log('Discover clicked');
console.log(slides);
theContent = `
<div class="modal">
<div class="modal__body">
<a href="#" id="close"><span class="modal__close"></span></a>
${Posts()}
</div>
</div>
`;
timelineModal.innerHTML = theContent;
onModalClose();
});
};
Any tips on how to achieve this?