Showing random div with javascript

后端 未结 2 1981
走了就别回头了
走了就别回头了 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.

    0 讨论(0)
  • 2021-01-16 00:07

    You need to import the jQuery library.

    Add

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    

    to your <head> tags before your javascript code.

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