Answer the question
In order to leave comments, you need to log in
How to find out the number of a div element inside a div?
For example, there is such a JSX element, you need to number each 'item-title' according to the hierarchy of its location inside the main div. Now I wrote it manually, but this is not the correct option, because the view depends on the background.
<div className='settings' id='settings'>
<div className='settings_item'>
<h3 className='item-title'>1. Почта </h3>
<div className='item_content'>
..content
</div>
</div>
<div className='settings_item'>
<h3 className='item-title'>2.Телефон </h3>
<div className='item_content'>
..content
</div>
</div>
</div>
const settingContent = document.getElementById('settings')
useEffect(() => {
settingContent?.childNodes.forEach((item, key) => {
const div = document.createElement('div')
div.innerHTML = `${key}`
console.log(item.childNodes.item(0))
item.childNodes.item(0).appendChild(div)
} )
}, [])
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question