Click here to Skip to main content
15,889,849 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP.NET
<div id="imgd" class="active" runat="server">
                                <img src="images/logo3.png" height="35" alt="Porto Admin" />
                            </div>
                            <div id="imgl" class="dnone" runat="server">
                                <img src="images/logo4.png" height="35" alt="Porto Admin" />
                            </div>




HTML
<div class="panel-body">
                                           <div id="demo-form" class="form-horizontal mb-lg">
                                               <div class="form-group mt-lg">
                                                   <div class="col-sm-3">
                                                       <input class="fixed dark btn btn-primary" type="button" id="btnd" value="Dark" onclick="changeCSS();" />
                                                   </div>
                                                   <label class="col-sm-6 control-label" style="text-align: center;"><b>Background Color </b></label>
                                                   <div class="col-sm-3">
                                                       <input class="fixed btn btn-info" type="button" id="btnl" value="Light" onclick="change();" />
                                                   </div>
                                               </div>
                                           </div>
                                       </div>


 <script type="text/javascript">>

          function changeCSS() {
              document.getElementById("divHTML").className = "fixed dark";

              document.getElementById('<%=imgl.ClientID%>').style.display = "none";
              document.getElementById('<%=imgd.ClientID%>').style.display = "block";

          }

        </script>

        <script>
            function change() {
                document.getElementById("divHTML").className = "fixed";
                document.getElementById("imgd").style.visibility = "hidden";
                document.getElementById("imgl").style.visibility = "visible";
                document.getElementById("imgl").className = "ldisp";
            }
        </script>
Posted
Updated 24-Jan-16 21:42pm
v2
Comments
dan!sh 25-Jan-16 3:43am    
Can you rephrase your question? It is not really clear what problem you are facing.
John C Rayan 25-Jan-16 4:45am    
Why cant you access a Div with runat=server from JavaScript? can you explain how do you mean?

1 solution

Use <%= %> in javascript because ASP.NET generates dynamic ID of controls. Try with below code:
ASP.NET
<div id="imgd" class="active"  runat="server">
	<img src="images/logo3.png" height="35" alt="Porto Admin" />
</div>

JavaScript
<script>
function change() {
	document.getElementById("<%=imgd.ClientID%>").style.visibility = "hidden";
}
</script>
 
Share this answer
 
v2
Comments
Sathish PS 26-Jan-16 7:02am    
thks, it's working
[no name] 26-Jan-16 7:05am    
Nice to hear. If it helps you, accept the answer..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900