
September 16th, 2009, 12:43 PM
|
|
Contributing User
|
|
Join Date: Jun 2009
Posts: 63
Time spent in forums: 22 h 23 m
Reputation Power: 1
|
|
I would recommend using a custom function to return class groupings, as the method 'getElementsByClassName' is not widely-supported yet.
Javascript Code:
Original
- Javascript Code |
|
|
|
window.onload = function() { var ent = document.getElementsByClassName('entry2').getEleme ntsByTagName('img'); for (i=0; i<ent.length; i++) ent[i].style.display = 'none'; // Hide everything. ent[0].style.display = 'block'; // Show the first one. }
[EDIT] Oh, and never use a direct call in your loops to an object's size; it will be re-calculated for every iteration of the loop. Also, do not use global variables inside of your loops, unless you are doing so intentionally. Initiate the 'i' with a 'var'. Use something like one of these, depending on your script.
Javascript Code:
Original
- Javascript Code |
|
|
|
for (var i=0, var len = ent.length; i<len; i++) var len = ent.length; for (var i=0; i<len; i++)
Last edited by Winters : September 16th, 2009 at 12:48 PM.
|