-6

in a recent post Load javascript after 2 clicks on website I asked about a javascript issue.

  $(function(){
          var count = 1
          $(document).click(function(){
            if(count<=2){
              count+=1;
           }
           else{
              alert("already clicked two times");
           }   
        });
     })

Problem is now that I want to have this javascript it inside script tags in my <head> but then this script wont work, can someone help me through how they would write their script? Thanks!!

Update:

  <head>
    <script>
  $(function(){
          var count = 1
          $(document).click(function(){
            if(count<=2){
              count+=1;
           }
           else{
              alert("already clicked two times");
           }
        });
     })
     </script>
  </head>
Community
  • 1
  • 1
user3637351
  • 11
  • 1
  • 5

2 Answers2

0

You should include jQuery library first:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
 $(function(){
   var count = 1
   $(document).click(function(){
     if(count<=2){
       count+=1;
     }
     else{
       alert("already clicked two times");
     }   
   });
 })  
</script>
dashtinejad
  • 6,193
  • 4
  • 28
  • 44
0
Please add JQuery library file..

<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
This code related to JQuery so without JQuery library we can not run this code.