/    Sign up×
Community /Pin to ProfileBookmark

How can I fade multiple divs?

I have the fade function down but I am dynamically creating a table with multiple rows. One cell in each table with have a unique div created..

<tr><td><div id=fade_99654>stuff</div></td><td>stuff</td></tr>
<tr><td><div id=fade_45215>stuff</div></td><td>stuff</td></tr>
<tr><td><div id=fade_78155>stuff</div></td><td>stuff</td></tr>
<tr><td><div id=fade_65324>stuff</div></td><td>stuff</td></tr>
<tr><td><div id=fade_81354>stuff</div></td><td>stuff</td></tr>
ect…

How can I run FadeThem() on all divs with a prefix of “fade_”?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@cgishackJan 15.2008 — do you want to fade the all at the same time, or randomly?

If you want to fade them all at the same time you can give them all the same "name" then [B]getElementsByName[/B]("[COLOR="Red"]someName[/COLOR]")

you then have an array and can simply modify your function to loop through the array.



Drew
Copy linkTweet thisAlerts:
@yamaharussauthorJan 15.2008 — I tried getElementsByName("someName") but it only affected the first div in the table and ignored the rest.

<tr><td><div id=fade>stuff</div></td><td>stuff</td></tr> //This one Faded

<tr><td><div id=fade>stuff</div></td><td>stuff</td></tr>

<tr><td><div id=fade>stuff</div></td><td>stuff</td></tr>

<tr><td><div id=fade>stuff</div></td><td>stuff</td></tr>

<tr><td><div id=fade>stuff</div></td><td>stuff</td></tr>
Copy linkTweet thisAlerts:
@cgishackJan 15.2008 — Here is some code you can use to help getElementsByName and loop/

<i>
</i>&lt;script&gt;

function fade()
{
var fades= document.getElementsByName("fadeDiv");

<i> </i>for (var i=0; i&lt;=fades.length-1; i++)
<i> </i>{
<i> </i> alert(fades[i].id + " can be faded")
<i> </i>}


}


&lt;/script&gt;


&lt;table&gt;
&lt;tr&gt;&lt;td&gt;&lt;div name="fadeDiv" id=fade_99654&gt;stuff&lt;/div&gt;&lt;/td&gt;&lt;td&gt;stuff&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div name="fadeDiv" id=fade_33442&gt;stuff&lt;/div&gt;&lt;/td&gt;&lt;td&gt;stuff&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div name="fadeDiv" id=fade_85434&gt;stuff&lt;/div&gt;&lt;/td&gt;&lt;td&gt;stuff&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div name="fadeDiv" id=fade_45667&gt;stuff&lt;/div&gt;&lt;/td&gt;&lt;td&gt;stuff&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;div name="fadeDiv" id=fade_24567&gt;stuff&lt;/div&gt;&lt;/td&gt;&lt;td&gt;stuff&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;


&lt;input type="button" value="Click Me" onclick="fade();" /&gt;


Drew
Copy linkTweet thisAlerts:
@cgishackJan 15.2008 — Maybe post your fade code to help us go further.

Drew
×

Success!

Help @yamaharuss spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...