Showing random div with javascript

后端 未结 2 1994
走了就别回头了
走了就别回头了 2021-01-15 23:15

So I want to show random divs, and I found this stackoverflow solution here: Showing random divs using Jquery

And the correct answer uses this code: http://jsfiddle.

2条回答
  •  执念已碎
    2021-01-15 23:54

    You are running the script before the HTML code for the body of the page has been parsed, so the elements doesn't exist yet.

    Put your code in the ready event of the page:

    $(document).ready(function(){
      // your Javascript code goes here
    });
    

    Also you are missing the include of the jQuery library, as Conner showed.

提交回复
热议问题