This is a migrated thread and some comments may be shown as answers.

How to Show a Div in JavaScript or JQuery

2 Answers 157 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Vuyiswa
Top achievements
Rank 1
Vuyiswa asked on 18 Jun 2012, 10:14 PM
Good Evening All 


I have a small issue here. I have a Div inside a TD that is defined like this 


<td    >
              <div id="divGoogleEarthMap" runat="server" [B]style="display:none" [/B]
                  >
                  <asp:HiddenField ID="HiddenField1" runat="server" />
                  <asp:ImageButton ID="GoogleEarthMap" runat="server" Height="100px"
                      OnClientClick="javascript:showimage('GoogleEarthMap'); return false;"
                      Width="100px" />
              </div>
          </td>


now the display style of this div is hidden. so i have a Javascript that runs when i close my popup. the first thing that javascript does is to populate two textboxes and show this div. It populate the textboxes nicely , but it fails to show or unhide the div. i have tried to set of code example using the normal javascript and also JQuery as depicted below 



 
$('#divGoogleEarthMap').css('display', "block;");
 


and



 
var div = document.getElementById("divGoogleEarthMap");<br>                div.style.display = "block";

 


or 


document.getElementById('divGoogleEarthMap').style.display = 'block';


but still my Element cant be displayed. 

Please note that i have a Sample Project that i can be supplied on request


Thanks 

2 Answers, 1 is accepted

Sort by
0
Accepted
Kevin
Top achievements
Rank 2
answered on 19 Jun 2012, 12:43 PM
Hello Vuyiswa,

The problem is that you turned the div into a server control and most likely you're using a master page or it's contained inside of another server control, so the id gets changed before it renders it to the browser. You should try the following, in order to show the div:

$('#<%=divGoogleEarthMap.ClientID%>').css('display', "block;");

I hope that helps.
0
Vuyiswa
Top achievements
Rank 1
answered on 19 Jun 2012, 12:55 PM
Thanks it worked
Tags
Ajax
Asked by
Vuyiswa
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Vuyiswa
Top achievements
Rank 1
Share this question
or