user159025
user159025

Reputation: 725

jQuery - get width of all li within a ul

I have a ul. Within the ul there are x number of li. Within the li there is a single image.

That is:

<ul>
    <li>image</li>
    <li>image</li>
    <li>image</li>
</ul>

I would like to be able to get the total width of the ul. Is this possible?

Thanks in advance.

Upvotes: 1

Views: 4380

Answers (3)

Anders Arpi
Anders Arpi

Reputation: 8397

$("ul").width()

Will get you the width of the ul element.

Upvotes: 0

ghusse
ghusse

Reputation: 3210

I'd say

var internaWidth = $("ul").width();
// or
var widthIncludingPadding = $("ul").outerWidth();
// or
var widthIncludingMargin = $("ul").outerWidth(true);

Depending on what you need

Upvotes: 1

Mahmut C
Mahmut C

Reputation: 433

First of all you should give an id to ul then this code may solve the problem:

<ul id="myul">
  <li>image</li>
  <li>image</li>
  <li>image</li>
</ul>

$(document).ready(function() {
   var totalWidth = $("#myul").width();
});

Upvotes: 0

Related Questions