I'm just starting to learn Javascript and I could use some help with this problem I'm having. I'm currently trying to add a p tag within a div tag that is in another div tag using DOM manipulation.
<div class='xxx'>
<div> <-- I was able to create this div through DOM manipulation
<p></p> <!-- Trying to add this tag through DOM manipulation
<p></p> <!-- Trying to add this tag through DOM manipulation
<p></p> <!-- Trying to add this tag through DOM manipulation
</div>
</div>
I searched on Stackoverflow and wasn't able to find what I was looking for. So far this is what I've tried among a few other methods.
Was able to create div here:
const mainFoodDiv = document.querySelector('.food-names')
for (let i = 0; i < foodCategoryArr.length; i++) {
const foodName = document.createElement('div')
mainFoodDiv.append(foodName)
}
Getting an error that says foodNameP.append is not a function:
const foodNameP = document.querySelectorAll('div > div')
for (let i = 0; i < foodCategoryArr.length; i++) {
const foodName = document.createElement('p')
foodName.textContent = foodCategoryArr[i]
foodNameP.append(foodName)
}
Can anyone guide me on where to go from here? I can only use pure javascript for this, no libraries or frameworks.