[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 651
  • Last Modified:

jQuery: Count list items

Using jQuery, how can I count the number of <li> in <ul id="mycarousel"> ?
<div class="gallery"> 
<ul id="mycarousel" class="jcarousel-skin-atlantica-small"> 
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-01.jpg" alt="Example" width="210" /></a></li> 
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-02.jpg" alt="Example" width="210" /></a></li> 
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-03.jpg" alt="Example" width="210" /></a></li> 
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-04.jpg" alt="Example" width="210" /></a></li> 
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-05.jpg" alt="Example" width="210" /></a></li> 
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-06.jpg" alt="Example" width="210" /></a></li> 
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-07.jpg" alt="Example" width="210" /></a></li> 
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-08.jpg" alt="Example" width="210" /></a></li> 
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-09.jpg" alt="Example" width="210" /></a></li> 
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-10.jpg" alt="Example" width="210" /></a></li> 
</ul> 
</div>

Open in new window

0
hankknight
Asked:
hankknight
1 Solution
 
clockwatcherCommented:
Use the length property of your returned selector:  $("#mycarousel li").length


<html>
<head>
<script language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></script>
<script language="javascript">
$(document).ready(function() {
        alert($("#mycarousel li").length);
});
</script>
</head>
<body>
<div class="gallery">
<ul id="mycarousel" class="jcarousel-skin-atlantica-small">
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-01.jpg" alt="Example" width="210" /></a></li>
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-02.jpg" alt="Example" width="210" /></a></li>
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-03.jpg" alt="Example" width="210" /></a></li>
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-04.jpg" alt="Example" width="210" /></a></li>
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-05.jpg" alt="Example" width="210" /></a></li>
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-06.jpg" alt="Example" width="210" /></a></li>
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-07.jpg" alt="Example" width="210" /></a></li>
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-08.jpg" alt="Example" width="210" /></a></li>
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-09.jpg" alt="Example" width="210" /></a></li>
<li> <a  href="http://www.example.com/"><img src="http://www.example.com/example-10.jpg" alt="Example" width="210" /></a></li>
</ul>
</div>
</body>
</html>

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now