abcd abcd - 3 months ago 7
Javascript Question

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>

Answer

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>
Comments