Well, if you literally want it to return the array:
Code:
function grabDivs() {
var ids = document.getElementById('content').getElementsByTagName('div');
return ids
}
With that in your script, anywhere (after the document is loaded) that you use 'grabDivs()' it will represent the array 'ids', ex:
Code:
alert(grabDivs()[3].innerHTML)
will launch an alert box with the 4th division's (assuming there is one in the collection/array) innerHTML (if any) displayed in it. Another strategy is to make the variable 'ids' global, then it will be the array and available for use:
Code:
window.onload = function() {
ids = document.getElementById('content').getElementsByTagName('div');
}
Here is an example of its use:
Code:
alert(ids[3].innerHML)
Bookmarks