hide Html elements by using javascript

前端 未结 5 2016
离开以前
离开以前 2020-12-30 01:15

How can i hide html elements by using javascript if i have this html page



test

相关标签:
5条回答
  • 2020-12-30 01:33

    You can use JQUERY : $('#1').hide()

    Great

    0 讨论(0)
  • 2020-12-30 01:39

    In addition to DevlshOne's answer, you could also use css to make it not display:

    var divOne = document.getElementById('1');
    divOne.style.display='none';
    

    There's a difference between the two. With visibility hidden, the space will still be consumed by the div, but you can't see it. With display='none', its as if its not there.

    Pick the better one for you.

    0 讨论(0)
  • 2020-12-30 01:39
    var divOne = document.getElementById('1');
    divOne.style.visibility = 'hidden';
    

    document.getElementById on MDN

    0 讨论(0)
  • 2020-12-30 01:46

    you will need to use something like this:

    document.getElementById("1").style.display = "none";
    
    0 讨论(0)
  • 2020-12-30 01:57

    Answers above are all basically correct, but you need to be aware of a difference between display = "none" & visibility = "hidden". With display "none" the element is removed from the layout of elements on the page. With visibility "hidden" the element still occupies its space, you just don't see it anymore.

    0 讨论(0)
提交回复
热议问题