Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title>STACKOVERFLOW - jQuery Click 5 then AJAX Load Something</title>
- <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
- </head>
- <body>
- <a href="index2.html">Click 5 times. Alert reload</a>
- <div id="yourDiv" style="margin-top:50px;"></div>
- <!-- JS SCRIPTS-->
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function() {
- i = 0; // Initialize Click Counter "i"
- $('a').click(function(event) {
- event.preventDefault(); // Prevent link from forwarding to page
- // Checks if link was clicked 5 times
- if(i == 5){
- $.ajax({
- url: 'index2.html',
- success: function(data){
- $('#yourDiv').html(data);
- }
- });
- } else {
- i++; // ELSE: Increment Click Counter "i"
- }
- });
- });
- </script>
- <!-- [end] JS SCRIPTS (Before Body Tag Closure)-->
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement