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");
});});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="div_containing_ul"></div>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;
}
Also in JavaScript:
- allow cross origin node
- select 2nd td jquery
- js replace all
- age validation jquery
- check if modal hide jquery
- how to sort string aray in ts
- jquery validator Url
- react-google-maps satelite
- js ask before close chrome
- datatable processing
- embed video by javascript
- jquery check if document loaded
- javascript add div before element
- coreui react change background color
- javascript online compiler
- confirm javascript
- install nuxt js
- javascript how to set cursor for whole page
- user defined exceptions in js
- loopback model count
- ajax post rest api example
- make string json object vue
- abstraction in javascript
- how to remove key value pair from object js