hankknight
asked on
jQuery: Third list items
Using jQuery I want to alert the contents of the 3rd list item:
Like this:
alert('<a href="http://www.example.com/"><img src="http://www.example.com/example-03.jpg" alt="Example" width="210" /></a>');
This does NOT work:
alert($("#mycarousel li").3.html());
Like this:
alert('<a href="http://www.example.com/"><img src="http://www.example.com/example-03.jpg" alt="Example" width="210" /></a>');
This does NOT work:
alert($("#mycarousel li").3.html());
<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>
Try... alert($("#mycarousel li:nth-child(3)).html()
ASKER
Thanks, but I am getting an error. Am I doing something wrong?
<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:nth-child(3)).html());
});
</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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.