ID attribute value must be unique in a document.
If you need multiple "hooks" sharing the same value use class attribute.

Try the following and you'll see the difference:

$(function() {
     var divcount = $("div.div2").length;
     alert("start=" + divcount);
   });
........
 <div class="div2">asdf</div>
 <div class="div2">asdf</div>
 <div class="div2">asdf</div>

MaurĂ­cio


-----Mensagem Original----- De: "bartee" <bar...@gmail.com>
Para: "jQuery (English)" <jquery-en@googlegroups.com>
Enviada em: segunda-feira, 19 de janeiro de 2009 15:25
Assunto: [jQuery] var divcount = $("div#div2").length; --- returns wrong value



My alert always returns "1" as the divcount value ???

What's up with that.. I have read and tried bunches of things.

What am I missing ????


<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en-AU">
<head>
 <title>Jquery Test</title>
 <script type="text/javascript" src="jquery-1.3.js"></script>
 <script type="text/javascript">
   $(function() {
     var divcount = $("div#div2").length;
     alert("start=" + divcount);
   });
 </script>
</head>
<body>
 <div id="div2">asdf</div>
 <div id="div2">asdf</div>
 <div id="div2">asdf</div>
</body>
</html>

Reply via email to