Vik_R
08-21-2007, 03:29 AM
I have a newbie question on getElementsByTagName. Here's some Javascript I'm working on.
It's finding the unordered list - when I step through it it with the FireBug plugin for FireFox, after the call to getElementById, I see the ul Metals_from_search, with 3 childnodes.
But after the call to getElementsByTagName, the links variable is shown with a length of zero.
What am I missing?
Thanks very much in advance to all for any info.
-Vik
Here's the Javascript:
function PrepareMetalsToBeAddedToListOfMetalsUserLikes(){
if( document.getElementById &&
document.getElementsByTagName ){
if( document.getElementById( 'Metals_user_may_want_to_add' ) ){
var Metals_from_search = document.getElementById( 'Metals_user_may_want_to_add' );
var links = Metals_from_search.getElementsByTagName( "a" );
for( var i=0; i < links.length; i++ ){
links[i].onclick = function(){
return Add_This_Metal(this);
};
}
}
}
}
Here is the html:
<ul id="metals_user_may_want_to_add">
<li>
<a href="http://localhost:8888/index.php/Add_metals/add_this_metal/9148" title = "Click to add this to the list of metals you like">
Copper</a>
</li>
<li>
<a href="http://localhost:8888/index.php/Add_metals/add_this_metal/9405" title = "Click to add this to the list of metals you like">
Iron</a>
</li>
<li>
<a href="http://localhost:8888/index.php/Add_metals/add_this_metal/14123" title = "Click to add this to the list of metals you like">
Gold</a>
</li>
</ul>
It's finding the unordered list - when I step through it it with the FireBug plugin for FireFox, after the call to getElementById, I see the ul Metals_from_search, with 3 childnodes.
But after the call to getElementsByTagName, the links variable is shown with a length of zero.
What am I missing?
Thanks very much in advance to all for any info.
-Vik
Here's the Javascript:
function PrepareMetalsToBeAddedToListOfMetalsUserLikes(){
if( document.getElementById &&
document.getElementsByTagName ){
if( document.getElementById( 'Metals_user_may_want_to_add' ) ){
var Metals_from_search = document.getElementById( 'Metals_user_may_want_to_add' );
var links = Metals_from_search.getElementsByTagName( "a" );
for( var i=0; i < links.length; i++ ){
links[i].onclick = function(){
return Add_This_Metal(this);
};
}
}
}
}
Here is the html:
<ul id="metals_user_may_want_to_add">
<li>
<a href="http://localhost:8888/index.php/Add_metals/add_this_metal/9148" title = "Click to add this to the list of metals you like">
Copper</a>
</li>
<li>
<a href="http://localhost:8888/index.php/Add_metals/add_this_metal/9405" title = "Click to add this to the list of metals you like">
Iron</a>
</li>
<li>
<a href="http://localhost:8888/index.php/Add_metals/add_this_metal/14123" title = "Click to add this to the list of metals you like">
Gold</a>
</li>
</ul>