How do I pull values ​​from all sub divs?

  • 0
    There is an element like this:
    <div id="spisok">
        <div id="elem1">
            <p id="elem1p">
                <br>Элемент 1
                <button>Кнопка</button>
            </p>
        </div>
        <div id="elem2">
            <p id="elem2p">
                <br>Элемент2
                <button>Кнопка</button>
            </p>
        </div>
    ....
        <div id="elemN">
            <p id="elemNp">
                <br>ЭлементN
                <button>Кнопка</button>
            </p>
        </div>
    </div>


    How can I go through a div with id = "spisok",
    to end up with a string / array of values ​​like:
    Element 1
    Element 2
    ...
    Element 3
    JavaScript Joshua Zavala, Mar 24, 2020

  • 1 Answers
  • 0
    const elementNames = Array
    .from(document.querySelectorAll('#spisok > div > p > br'))
    .map(n => n.nextSibling.textContent.trim());
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!