admin管理员组文章数量:1323330
$(function () {
$("#divLimitPrice").hide();
$('#divLimitPrice').hide(); //even tried it with ''
});
<div id="divLimitPrice">Limit Price<br />
<asp:TextBox ID="txtLimitPrice" runat="server"></asp:TextBox>
</div>
My understanding is that this is supposed to work..... it wants to fight me. Any way to beat it into submission? Thanks all! - G
$(function () {
$("#divLimitPrice").hide();
$('#divLimitPrice').hide(); //even tried it with ''
});
<div id="divLimitPrice">Limit Price<br />
<asp:TextBox ID="txtLimitPrice" runat="server"></asp:TextBox>
</div>
My understanding is that this is supposed to work..... it wants to fight me. Any way to beat it into submission? Thanks all! - G
Share asked Jun 9, 2013 at 23:02 gmattesongmatteson 794 silver badges13 bronze badges 4-
You've included jQuery before that JS snippet, right? Also JS needs to be in
<script>
tags (although that could have been left out for the sake of conciceness) – Bojangles Commented Jun 9, 2013 at 23:06 - Here's the full script- thanks! <script type="text/javascript"> $(function () { $('#divLimitPrice').hide(); }); function OnSelection(me) { // find the selected value var SelectedValue = jQuery('option:selected', me).attr('value'); // if selected value = x then... if (SelectedValue == "Limit") jQuery("#divLimitPrice").show(); else jQuery("#divLimitPrice").hide(); } </script> – gmatteson Commented Jun 9, 2013 at 23:13
- That should be edited into your post - there's a button underneath the tags to do so – Bojangles Commented Jun 9, 2013 at 23:14
- Here is your code: jsfiddle/erdemkeren/VVfA3/7 It didn't try to fight. Seems submissively doing what it must... I don't want to say "check your jquery link" but there should be some bug hidden between your code snippets.. – Hilmi Erdem KEREN Commented Jun 9, 2013 at 23:17
3 Answers
Reset to default 5It will flicker if you use JS as the script has to load first which means until it's loaded the div will remain visible on the DOM.
The easiest way to do this is to give your div a CSS class of display none like following. That way when the page is loaded it will already be hidden.
<div id="divLimitPrice" class="hide-div">Limit Price<br />
hide-div {
display: none;
}
When you need it to be shown you can use jQuery as follows:
$('#divLimitPrice').removeClass('hide-div')
Hope this helps.
Try this:
<div id="divLimitPrice">Limit Price<br />
<asp:TextBox ID="txtLimitPrice" runat="server"></asp:TextBox>
</div>
<script>
$(function () {
$("#divLimitPrice").hide();
});
</script>
I think your problem is the JS is executing before the page loads.
Try this:
$(document).ready(function(){
$("#divLimitPrice").hide();
});
本文标签: javascriptHide Div Control on Page LoadStack Overflow
版权声明:本文标题:javascript - Hide Div Control on Page Load - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742140181a2422547.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论