最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do i hide div in asp.net mvc - Stack Overflow

programmeradmin0浏览0评论

I have 3 div which are:

<div class="widgetbox" id="divone">Content 1</div>

<div class="widgetbox" id="divtwo">Content 2</div>

<div class="widgetbox" id="divthree">Content 3</div>

I need to hide two of these div so that I can make a condition to decide which to appear and which to hide later on. I tried to hide it like below, but it doesn't work. I think I'm using mvc 4. sorry for bad english.

<script type='text/javascript'>
    $("#divtwo").hide();
    $("#divthree").hide();    
</script>

I have 3 div which are:

<div class="widgetbox" id="divone">Content 1</div>

<div class="widgetbox" id="divtwo">Content 2</div>

<div class="widgetbox" id="divthree">Content 3</div>

I need to hide two of these div so that I can make a condition to decide which to appear and which to hide later on. I tried to hide it like below, but it doesn't work. I think I'm using mvc 4. sorry for bad english.

<script type='text/javascript'>
    $("#divtwo").hide();
    $("#divthree").hide();    
</script>
Share Improve this question edited Aug 21, 2016 at 2:39 ekad 14.6k26 gold badges46 silver badges48 bronze badges asked May 25, 2015 at 10:06 abcdabcd 1091 gold badge2 silver badges13 bronze badges 2
  • Does your project have jQuery reference? – Rahul Nikate Commented May 25, 2015 at 10:10
  • Define "doesn't work". Does it throw an error? Does it work if you run those mands in the console after page-load? Where is your script-tag located in the HTML document? – ivarni Commented May 25, 2015 at 10:23
Add a ment  | 

2 Answers 2

Reset to default 4

Here you get two answers:

1)

<script type='text/javascript'>
    $(document).ready(function(){
        $("#divtwo").hide();
        $("#divthree").hide();
    });
</script>

2) try this one. No need any references.

<script type='text/javascript'>
    window.onload=function(){
        document.getElementById("divtwo").style.display='none';
        document.getElementById("divthree").style.display='none';
    }
</script>

First you need to add jQuery reference. Here you is way to get latest jQuery in your project

<script src="http://code.jquery./jquery-latest.min.js" type="text/javascript"></script>

then your code will work for .hide()

<script type='text/javascript'>
    $("#divtwo").hide();
    $("#divthree").hide();    
</script>
发布评论

评论列表(0)

  1. 暂无评论