Show/Hide div, with plain JS

后端 未结 6 578
独厮守ぢ
独厮守ぢ 2021-01-19 23:23

My CSS:

#a_x200{
    visibility: hidden;
    width: 200px;
    height: 200px;
    background-color: black;
}

My JS:



        
相关标签:
6条回答
  • 2021-01-19 23:56

    You're using visibility: hidden to hide it, then attempting to use the display CSS property to make it visible. They're two completely separate properties, changing one won't magically change the other.

    If you want to make it visible again, change the value of the visibility property to visible:

    document.getElementById('a_x200').style.visibility = 'visible';
    
    0 讨论(0)
  • 2021-01-20 00:03

    try this:

    document.getElementById('a_x200').style.visibility = 'visible';
    
    0 讨论(0)
  • 2021-01-20 00:07

    You can try this code:

    HTML Code:
            <div id="a_x200" style="display:none;">asd</div>
            <input type="button" class="button_p_1" onclick="showStuff('a_x200');"></input>
    
    Java script:
    
    <script type="text/javascript">
    function showStuff(id) {
            document.getElementById(id).style.display = "block";
    }
    </script>
    

    Try this code it will solve your problem.

    0 讨论(0)
  • 2021-01-20 00:15

    try this...

    function showStuff(id) {
        document.getElementById(id).style.display = 'block'; // OR
        document.getElementById(id).style.visibility = 'visible'; 
    } 
    

    edit

    If you notice on your button click onclick="showStuff('a_x200');". you have already sent the id as a parameter to your function.. so i am taking the parameter and using it.

    in your case have the parameter but not using it... though it does the samething...

    OR u can do this

    <input type="button" class="button_p_1" onclick="showStuff();"></input>  // omitting double 'n'
    
    function showStuff() {
        document.getElementById('a_x200').style.display = 'block';
    }  // missing curly bracket 
    

    this both does the same thing

    0 讨论(0)
  • 2021-01-20 00:18

    Here you can se one example i created in jquery Show/Hide using jquery .

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
    <style>
    .slidingDiv {
        height:300px;
        background-color: #99CCFF;
        padding:20px;
        margin-top:10px;
        border-bottom:5px solid #3399FF;
    }
    
    .show_hide {
        display:none;
    }
    
    </style>
    <script type="text/javascript">
    
    $(document).ready(function(){
    
            $(".slidingDiv").hide();
            $(".show_hide").show();
    
        $('.show_hide').click(function(){
        $(".slidingDiv").slideToggle();
        });
    
    });
    
    </script>
    
    <a href="#" class="show_hide">Show/hide</a>
    <div class="slidingDiv">
    Fill this space with really interesting content. <a href="#" class="show_hide">hide</a></div>​
    
    0 讨论(0)
  • 2021-01-20 00:19

    your input is miss spled

    Should be like this:

    My JS

    <script type="text/javascript">
    function showStuff(a_x200) {
            document.getElementById(a_x200).style.display = 'block';
    }
    </script>
    

    My Html

    <div id="a_x200">asd</div>
    <innput type="button" class="button_p_1" onclick="showStuff('a_x200');"></input>
    
    0 讨论(0)
提交回复
热议问题