Advertisement

08.25.2008 at 09:55PM PDT, ID: 23677461 | Points: 250
[x]
Attachment Details

document.getElementById and dynamic styles

Asked by susanBuck in Dynamic HTML (DHTML), JavaScript

Tags: ,

I'd like to use getElementById and style in a function, passing in the style as a dynamic paramater - Like in the example function below where whichStyle is the paramater for the dynamic style, and I pass in top.

ie, what i want to create is : document.getElementById(whichDiv).style.top = value + "px";  
where top can actually be a variable I pass in.

Is this possible, if so, how?Start Free Trial
1:
2:
3:
4:
5:
6:
function dynamicallySetStyle(whichDiv,whichStyle,value) {
   document.getElementById(whichDiv).style.whichStyle = value + "px";
  
}
 
dynamicallySetStyle("myDiv","top",100);
[+][-]08.25.2008 at 10:37PM PDT, ID: 22311818

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.25.2008 at 10:39PM PDT, ID: 22311821

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-44 / EE_QW_2_20070628