Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

jquery nested ul li

function buildList(data) {
    var $ul = $('<ul></ul>');
    for (const key in data) {
        var $child = $('<li></li>');
        $ul.append($child)
        if (typeof data[key] === 'object') {
            $child.text = $child.text(key);
            $child.append(buildList(data[key]));
        } else {
            $child.text = $child.text(key + ' : ' + data[key]);
        }
    }
    return $ul;
}
Comment

jquery nested ul li

jQuery(document).ready(function($) {

$.get('url', function(data){

            var $ul = $('<ul></ul>');

            function getList(item, $list) {

                $.each(item, function (key, value) {
                    var $li = $('<li />');
                    $li.append($('<a href="#">' + key + '</a>'));

                    var $subul = $("<ul/>");

                    $.each(value, function(i) {
                        var subli = $('<li/>')
                        .text(value[i])
                        .appendTo(subli);
                    });
                    $subul.append(subli);


                    $li.append($subul)

                });
            }
            getList(data, $ul);
            $ul.appendTo("div_containing_ul");
    });});
Comment

jquery nested ul li

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="div_containing_ul"></div>
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript program german to english translation 
Javascript :: can you wrap redux provider within react.strictmode 
Javascript :: coffeescript float to two decimal places 
Javascript :: const data = event.currentTarget.value 
Javascript :: dragula filter 
Javascript :: how to start v-for on a specific index 
Javascript :: int cating javascript 
Javascript :: str_word_count php js 
Javascript :: get minutes with 2 numbers 
Javascript :: express js continous GET /json/version 
Javascript :: javascript convert array of objects to array of uri 
Javascript :: refresh javascript using require 
Javascript :: Javascript Make your console talk! 
Javascript :: query sequnce graphql 
Javascript :: encriptar exadecimal con cryptojs 
Javascript :: what does js stand for 
Javascript :: youtbe trailer npm 
Javascript :: setup node and mongodb on centos 7 using npm 
Javascript :: reactjs web3 components 
Javascript :: News Application With Angular and Material Design 
Javascript :: parallaxprovider 
Javascript :: how do i activate my mangekyou sharingan 
Javascript :: greater than x but less than y es6 
Javascript :: how to use yes no statement with alert in tampermonkey 
Javascript :: check a divide condition and print msg javascript 
Javascript :: create react app cloudfront invalidation 
Javascript :: node js firebird example 
Javascript :: DecoupledEditor.create 
Javascript :: chanhe button yext jquery 
Javascript :: ck editr value submit jquery ajax 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =