Answer the question
In order to leave comments, you need to log in
How to create a menu from multiple lists?
Hello! I got a little problem.
There are n ul lists , from which I form an adaptive menu. It looks like this:
var leftMenuContent = $('#header .menuList'); // Соберём все ссылки в шапке
$('<nav />', {
id: 'leftMenu',
html: leftMenuContent
}).prependTo('body');
<nav id="leftMenu">
<ul class="menuList" data-title="О нас">
<li></li>
<li></li>
</ul>
<ul class="menuList" data-title="Выберите услугу">
<li></li>
<li></li>
</ul>
<ul class="menuList">
<li></li>
<li></li>
<li></li>
</ul>
</nav>
<nav id="leftMenu">
<h4>О нас</h4>
<ul class="menuList" data-title="О нас">
<li></li>
<li></li>
</ul>
<h4>Выберите услугу</h4>
<ul class="menuList" data-title="Выберите услугу">
<li></li>
<li></li>
</ul>
<ul class="menuList">
<li></li>
<li></li>
<li></li>
</ul>
</nav>
Answer the question
In order to leave comments, you need to log in
jsfiddle.net/koceg/57bunxgp
$('#leftMenu .menuList').each(function (i, el) {
var $el = $(el),
title = $el.data('title');
if (title)
{
$el.before('<h4>' + title + '</h4>');
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question