abcd
abcd

Reputation: 109

How do i hide div in asp.net mvc

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>

Upvotes: 0

Views: 20808

Answers (2)

Jaimin Soni
Jaimin Soni

Reputation: 1071

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>

Upvotes: 4

Rahul Nikate
Rahul Nikate

Reputation: 6337

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>

Upvotes: 0

Related Questions