1 - You should not use id="title" or any other attribute name; 2 - You should not use the same id on more than one element (id=identifier, i.e. sould be unique).
Fábio Miranda Costa Engenheiro de Computação http://meiocodigo.com On Mon, Apr 13, 2009 at 8:45 PM, Mike <[email protected]> wrote: > > When I try to select an element by id (where there > 1 elements with > the same id on the page) from within a specific element, I get the > following error message: > > secondListNode.getElementById("title") is null > > Should this be an error? > > It would be handy if this worked, because then I wouldn't have to use > selectors. > > p.s. I love MooTools. Well done. Up until recently, I was a software > engineer at Google. I miss all their tools, but MooTools gets me 95% > of the way there. It's a high quality framework. > > <ul> > <li id="list1"> > <div id="title">Title 1</div> > <div id="content">Content 1</div> > </li> > <li id="list2"> > <div id="title">Title 2</div> > <div id="content">Content 2</div> > </li> > </ul> > > <script type="text/javascript"> > > var firstListNode = $("list1"); > var firstListTitle = firstListNode.getElementById("title").innerHTML; > alert("First List Title: " + firstListTitle); > > var secondListNode = $("list2"); > var secondListTitle = secondListNode.getElementById > ("title").innerHTML; > alert("Second List Title: " + secondListTitle); > > </script>
