Render value dynamically of div containing specific class via ejs

Viewed 26

My problem is that I would want to select only the data from a div that contains the class "selected-nevoias", and introduce it to span inside another div.

Here I add the class to a div I want to select after I click on it:

<script>
    $(".lista-nevoiasi .nevoias").each(function () {
        $(this).click(function () {
            if (!$(this).hasClass("selected-nevoias") && $(".lista-nevoiasi .nevoias").hasClass(
                    "selected-nevoias")) {
                $(".lista-nevoiasi .nevoias").removeClass("selected-nevoias")
                $(this).toggleClass("selected-nevoias")
            } else(
                $(this).addClass("selected-nevoias")
            )
        });
    });
</script>

This one is the div that can be selected and has data seeded from my mongoose schema and a JSON file:

<% for(let nevoias of nevoiasi) {%>
            <div class=" container nevoias">
                <img src="/img/greybg.jpg" alt="">
                <div class="info">
                    <p><%= nevoias.nume %> </p>
                    <p><%= nevoias.varsta %> </p>
                </div>
            </div>
            <% } %>

And here is the div where I want to display the data from only the selected previous div (that has a specific class I assigned to it), in theory, I would want to dynamically allocate data to the img, all the spans, and every li tags inside this div:

<div class="info-div">
                    <img src="/img/greybg.jpg" alt="">
                    <div class="info">
                        <p>Nume: <span>Marian M.</span></p>
                        <P>Vărstă: <span>56 ani</span></P>
                        <p>Telefon: <span>0753358946</span></p>
                        <p>Adresă: <span>Str. Grigore Ureche, Nr. 3, Oradea</span></p>
                        <p>Necesităţi: </p>
                        <span>
                            <ul>
                                <li>Măncare</li>
                                <li>Cazare</li>
                                <li>Haine</li>
                            </ul>
                        </span>
                    </div>
                </div>

I would appreciate some help with this. Thank you!

0 Answers
Related