playing arround with arrays i discovered two different kinds of arrays.
Have look on this code:
Code:
var temp = gallery_list.getElementsByTagName('dd');
var tumb = new Array();
for(var i = 0; i < temp.length; i++){
if(temp[i].className == 'view_button')
tumb.push(temp[i]);
}
view_button_list = tumb;
The temp array is as you can see provided by the 'getElementsByTagName'-Method.
The tump array is put together by a custom loop.
If i look with firebug at the arrays, i get different readings(see attached image01.jpg). While 'temp' got its length property and its unique methods.
'tumb' does not. How come? Whats the difference?
And how do i make a custom element array like one that is created by getElementsByTagName.
It is more common to convert a node collection to an array.
Code:
var A=[],tags=document.getElementsByTagName('dd');
A=A.slice.call(tags,0,tags.length);
A is an array of the elements in the tags node list.
You can use any array methods to manipulate the array,
but it is no longer live, as a node list is.
It is a 'snapshot' of the document at the time the array was created.
Bookmarks