/    Sign up×
Community /Pin to ProfileBookmark

Changing styles of divs

Is there a way to change the styles of div with ids not included as selectors in the style sheet? I’ve been using document.getElementById(”).style but this can no longer do because the divs are generated on run-time.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@jamJun 21.2009 — Can you give us an example of the div generation? (What are you doing to generate the divs, because it could be sorted there).

Cheers,

Jamey
Copy linkTweet thisAlerts:
@alain_b4authorJun 21.2009 — function Show_Box()

{

for(Counter=0; Counter<Row; Counter++)

for(Counter_2=0; Counter_2<Column; Counter_2++)

{

ID=Counter*Column+Counter_2;

document.getElementById('Announcements').innerHTML+="<div id='Box_"+ID+"' class='Box' onmouseover='Select(""+ID+"")' onmouseout='Deselect()' onclick='Fade_Out(""+ID+"");Reset()' style='position: absolute;'><div id='Date_"+ID+"' class='Date'>"+Date[Title.length-1-ID]+"</div>"+Title[Title.length-1-ID]+"</div>";

document.getElementById('Box_'+ID).style.left=Corner_Left+Counter_2*
(Box_Width+Box_Margin)+'px';

document.getElementById('Box_
'+ID).style.top=Corner_Top+Counter*(Box_Height+Box_Margin)+'px';

}

}

this is how i generate the divs. I could already change the left value of the divs because of the style attribute I placed on the divs but is there a better way?
Copy linkTweet thisAlerts:
@jamJun 21.2009 — Okay, the only thing i can think of is using an array to store references to your DIV elements. But that's not ideal, where is it you need to change the style attributes of the div?(i'm assuming in some other function, etc.)...

As for actually changing the style defs, do you need to change one box idependantly of the others?
×

Success!

Help @alain_b4 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.18,
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,
)...