M
M
Mauster2015-10-04 00:35:18
css
Mauster, 2015-10-04 00:35:18

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>

Thanks in advance!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Antonov, 2015-10-04
@Sadist07

jQuery(document).ready(function($) {
  var li = $('li');
  li.each(function() {
    var a = $(this).width();
    alert(a);
  });
});

V
Vitaly Inchin ☢, 2015-10-04
@In4in

var allWidth = 0;

[].forEach.call(document.querySelectorAll("li"), function(e){
   allWidth += e.offsetWidth;
});

alert(allWidth);

A
Alexander, 2015-10-04
@kentuck1213

Maybe just calculate the width of ul ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question