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>
ekad
  • 14,436
  • 26
  • 44
  • 46
abcd
  • 109
  • 1
  • 2
  • 13
  • Does your project have jQuery reference? – Rahul Nikate May 25 '15 at 10:10
  • Define *"doesn't work"*. Does it throw an error? Does it work if you run those commands in the console after page-load? Where is your script-tag located in the HTML document? – ivarni May 25 '15 at 10:23

2 Answers2

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>
captainsac
  • 2,484
  • 3
  • 27
  • 48
Jaimin Soni
  • 1,061
  • 1
  • 13
  • 29
0

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

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

then your code will work for .hide()

<script type='text/javascript'>
    $("#divtwo").hide();
    $("#divthree").hide();    
</script>
Community
  • 1
  • 1
Rahul Nikate
  • 6,192
  • 5
  • 42
  • 54