Question

I'm trying to get the innerText of all the children in the selected node.

So if user clicks on one of the ULs I would like to get the text of that UL and any children (ULs and/or LIs) and write it to the console.

$("#removeNode").click(function (e) {
    var treeview = $("#treeview").data("kendoTreeView");
    var selectedNode = treeview.select();

    console.log(selectedNode.text());
});

The above console.log give me "LLC-A Alpine LLC-B Seminole LLC-C Commons Chase" as an example but I need to list each individually as:

LLC-A
Alpine
LLC-B
Seminole
LLC-C
Commons
Chase

Sample Unorded List:

<ul class="k-group" style="border-style: none;">
<li class="k-item k-first k-last" data-id="BASE" id="BASE" data-uid="31f1f67d-89f9-40e7-b646-29a9597056c7">
    <div class="k-top k-bot"><span class="k-icon k-minus"></span><span class="k-in" data-expanded="true">Test</span></div>
    <ul class="k-group" style="border-style: none;">
        <li class="k-item k-last" data-uid="aec27c8c-ca89-49e8-bfd3-0cede391a55e">
            <div class="k-bot"><span class="k-icon k-minus"></span><span class="k-in" data-expanded="true">LLC-A</span></div>
            <ul class="k-group" style="border-style: none;">
                <li class="k-item" data-uid="78810005-52ad-42ae-92dd-7245b6960eb6">
                    <div class="k-top"><span class="k-icon k-minus"></span><span class="k-in" data-expanded="true">LLC-B</span></div>
                    <ul class="k-group" style="border-style: none;">
                        <li class="k-item" data-uid="bd9866fb-c997-41ae-a4c2-d5576f391a9c">
                            <div class="k-top"><span class="k-icon k-minus"></span><span class="k-in" data-expanded="true">LLC-C</span></div>
                            <ul class="k-group" style="border-style: none;">
                                <li class="k-item" data-uid="31c48db8-c9d2-4f40-b2ba-f42197811e56">
                                    <div class="k-top"><span class="k-icon k-minus"></span><span class="k-in" data-expanded="true">LLC-D</span></div>
                                    <ul class="k-group" style="border-style: none;">
                                        <li class="k-item k-last" data-uid="778c3538-7fbc-4daf-8b7d-b6f3cca5b6fd">
                                            <div class="k-bot"><span class="k-in">Beacon</span></div>
                                        </li>
                                    </ul>
                                </li>
                                <li class="k-item k-last" data-uid="f9e673c0-902c-4ede-b5c4-ccd2232391a4">
                                    <div class="k-bot"><span class="k-in">Willows</span></div>
                                </li>
                            </ul>
                        </li>
                        <li class="k-item" data-uid="c0f42f30-cb84-4f66-a37e-e96a0b0cfcbf">
                            <div class="k-mid"><span class="k-in">Chase</span></div>
                        </li>
                        <li class="k-item k-last" data-uid="7b7053bd-38ee-4312-9e78-484b4da48e0d">
                            <div class="k-bot"><span class="k-icon k-minus"></span><span class="k-in" data-expanded="true">LLC-F</span></div>
                            <ul class="k-group" style="border-style: none;">
                                <li class="k-item" data-uid="c0dad4b9-1839-4dca-ac1f-2fe9fc2df5ed">
                                    <div class="k-top"><span class="k-in">Seminole</span></div>
                                </li>
                                <li class="k-item k-last" data-uid="8c4073be-4b8c-4036-a85c-efe36bda1466">
                                    <div class="k-bot"><span class="k-in">Commons</span></div>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </li>
                <li class="k-item k-last" data-uid="39644343-4b0c-4be0-be08-701f63096195">
                    <div class="k-bot"><span class="k-in">Alpine</span></div>
                </li>
            </ul>
        </li>
    </ul>
</li>

Was it helpful?

Solution

The text jQuery function will return the inner text of a DOM node and all its children. In this particular case you can just split the text and then join it back. Here is what I mean:

http://jsbin.com/edahit/1/edit

OTHER TIPS

This is what I ended up doing and it appears to be working....so far.

           var lis = $(".k-in", selectedNode);

            for (var i = 0; i < lis.length; i++) {
                var name = lis[i].innerText;
                console.log(name);
            }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top