How to show / hide multiple elements at the same time with javascript

前端 未结 5 433
名媛妹妹
名媛妹妹 2021-01-22 01:11

So, I have this between my head tags



        
5条回答
  •  北恋
    北恋 (楼主)
    2021-01-22 01:54

    The JavaScript is executed before the divs are in the DOM. The standard way to do something after the DOM is ready is to use jQuery's $(document).ready(function () { });, but there are other ways as well.

    The oldschool way is to use .

    Here's a newer way (edit: put display:none into CSS):

    HTML:

    hello

    CSS:

    .javascript_needed {display:none;}
    

    JavaScript:

    ​$(document).ready(function () {
        $('.javascript_needed').show();
    });
    ​
    

提交回复
热议问题