Show/Hide div, with plain JS

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

My CSS:

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

My JS:



        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    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

      // omitting double 'n'
    
    function showStuff() {
        document.getElementById('a_x200').style.display = 'block';
    }  // missing curly bracket 
    

    this both does the same thing

提交回复
热议问题