Answer the question
In order to leave comments, you need to log in
How to find out the width of all li?
Hello! How to get total width of inner li elements?
It is necessary that the script count the internal li and find out the total width
<nav>
<ul>
<li>
<a href="">Создание сайтов</a>
<ul>
<li>
<a href="">Простой сайт</a>
</li>
<li>
<a href="">Сайт-визитка</a>
</li>
<li>
<a href="">Малый бизнес</a>
</li>
<li>
<a href="">Лендинг</a>
</li>
<li>
<a href="">Официальный сайт</a>
</li>
</ul>
</li>
<li class="active">
<a href="">Продвижение</a>
<ul>
<li>
<a href="">ТОП-10</a>
</li>
<li>
<a href="">ТОП-9</a>
</li>
<li>
<a href="">ТОП-8</a>
</li>
<li>
<a href="">ТОП-7</a>
</li>
</ul>
</li>
</ul>
</nav>
Answer the question
In order to leave comments, you need to log in
jQuery(document).ready(function($) {
var li = $('li');
li.each(function() {
var a = $(this).width();
alert(a);
});
});
var allWidth = 0;
[].forEach.call(document.querySelectorAll("li"), function(e){
allWidth += e.offsetWidth;
});
alert(allWidth);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question