admin管理员组文章数量:1414908
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.
本文标签: javascriptWhy jquery class selector select items that has part of the classnameStack Overflow
版权声明:本文标题:javascript - Why jquery class selector select items that has part of the classname? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745178363a2646350.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论