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>
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>
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;
}
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");
});});
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us