i have a div :
<div id="postreply">
<asp:Label ID="lbStatus" CssClass="input-large1" runat="server" Text="Close" Width="600px"></asp:Label>
</div>
i try to hide div when page load :
<script type="text/javascript">
window.onload = function() {
var x = document.getElementById('lbStatus').innerText;
if(x == "Close"){
$("#postreply").hide();
}
}</script>
anyone help me hide this div with lbStatus.Text = Close
i have a div :
<div id="postreply">
<asp:Label ID="lbStatus" CssClass="input-large1" runat="server" Text="Close" Width="600px"></asp:Label>
</div>
i try to hide div when page load :
<script type="text/javascript">
window.onload = function() {
var x = document.getElementById('lbStatus').innerText;
if(x == "Close"){
$("#postreply").hide();
}
}</script>
anyone help me hide this div with lbStatus.Text = Close
Share Improve this question edited Jul 5, 2013 at 7:50 Danny Beckett 20.7k25 gold badges112 silver badges142 bronze badges asked Jul 5, 2013 at 7:47 beginerdeveloperbeginerdeveloper 8454 gold badges20 silver badges45 bronze badges 7 | Show 2 more comments5 Answers
Reset to default 6Can't you simply use CSS for this?
#postreply {
display: none; /* onLoad your div will be hidden */
}
Try this, once with $(document).ready
, it executes when HTML-Document is loaded and DOM is ready where as window.onload
executes when complete page is fully loaded, including all frames, objects and images
$(document).ready(function() {
if($("#lbStatus").val() == "Close"){
$("#postreply").hide();
}
});
As you are using Asp.Net
try to use ClientId
property
$(document).ready(function() {
if($("#<%=lbStatus.ClientID%>").val() == "Close"){
$("#postreply").hide();
}
});
Changed <%=lbStatus.ClientID%>
instead of lbStatus
Reference: http://4loc.wordpress.com/2009/04/28/documentready-vs-windowload/
You mix up between pure javascript and jQuery.
If you not include jquery library, use pure javascript.
<script type="text/javascript">
window.onload = function() {
var x = document.getElementById('lbStatus').innerText;
if(x == "Close"){
// $("#postreply").hide();
document.getElementById('postreply').style.display = 'none';
}
}
</script>
Looks like you need to remove the #
sign.
$('postreply').hide();
Or, vanilla Javascript:
document.getElementById('postreply').style.display = 'none';
You can hide it from the start.
Either with javascript: document.getElementById('lbStatus').style.display = 'none';
and to get it back "visible" use document.getElementById('lbStatus').style.display = "";
or with css: #lbStatus{display: none;}
document.getElementById('postreply').style.display = 'none';
? Then it's not visible and you can change it back when you need. – Sergio Commented Jul 5, 2013 at 7:49ClientIdMode = Static
for your label and check the same code. – Chamaququm Commented Jul 5, 2013 at 8:01