views:

115

answers:

2

Hi, I am applying style to div using javascript it appears well at the first time but when I click an image to open a virtual window the applied css goes away.

How can I apply style using script that stays forever.

**There is no way left for me to apply any style at design time because I am using ready made user control and I get ID for the DIV only at run time.

Any Idea??

Here is the script I am using...

window.onload = changeDivOverflow;
       function  changeDivOverflow()
        {
            var treeDiv = document.getElementById('T_ctl00contentMainctl04tvw');
            treeDiv.style.overflow = "auto";

        }
+1  A: 

Since you are using ASP.NET, but I cannot see all your full code, I can only assume that your DIV has a runat="server" tag and that's why you cannot get the ID on the client side.

If this is the case, you may consider the following change to get the treeDiv:

var treeDiv = document.getElementById("<%= tvw.ClientID %>");
ichiban
A: 

All styles you apply using javascript and DOM calls, apply only to element you are applying it. In your example it will be only element with ID = 'T_ctl00contentMainctl04tvw'

If you want to reuse that style for more than one element, you should create a CSS class and store that style there. Then apply that class for every element you want. If you want to do it with script, then you should:

var treeDiv = document.getElementById('T_ctl00contentMainctl04tvw');
treeDiv.className = "your-class";
skrat