if i have :
<div class="carBig"></div>
and
<div class="car"></div>
and $(".car").size();
i get 2 items ..
if i have :
<div class="carBig"></div>
and
<div class="car"></div>
and $(".car").size();
i get 2 items ..
Share Improve this question edited Nov 26, 2008 at 13:03 bobince 537k110 gold badges672 silver badges844 bronze badges asked Nov 26, 2008 at 13:01 Moran HelmanMoran Helman 18.6k4 gold badges25 silver badges26 bronze badges2 Answers
Reset to default 4What version of jquery are you using?
Using this code:
<html><head><title>Testing</title>
<script type="text/javascript" src="/js/jquery/jquery-1.2.6.min.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
$(".car").each(function() {
$("#carResults").append($(".car").size());
$("#carResults").append($(this).text());
});
});
</script>
</head><body>
<div class="carBig">Big Car</div>
<div class="car">Regular Car</div>
<div id="carResults"></div>
</body></html>
My output document looked like this:
Big Car
Regular Car
1Regular Car
Mine only found 1 element, the one with the class of "car"...
I think you may have something funky somewhere that's throwing it off. If I run this very simple example, it works just as expected.
<html>
<head>
</head>
<script type="text/javascript" src="jquery-1.2.6.pack.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".car").hide();
});
</script>
<body>
<div id=container>
<div class="carBig">Car Big</div>
<div class="car">Car</div>
</div>
</body>
</html>
You could try posting the rest of your html to see if we can figure it out.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745178364a4615303.html
评论列表(0条)