www.webdeveloper.com
Results 1 to 3 of 3

Thread: [HELP] How to call a function with a click of a button

Hybrid View

  1. #1
    Join Date
    Jul 2013
    Posts
    2

    [HELP] How to call a function with a click of a button

    How would I call

    Code:
    setTimeout(
            function(){
              
              $('#loading').replaceWith($('#amnt'));
              $('#amnt').show();
              
            },
            5000
          );
    to start when I click a button
    Code:
    <a href="#myModal" role="button" class="btn btn-custom" data-toggle="modal"> Counter</a>

  2. #2
    Join Date
    Jul 2013
    Posts
    66
    By putting it into a function that is called upon the click event. You can use the onclick handler right away:

    Code:
    <a href="#myModal" id="counterLink" role="button" class="btn btn-custom" data-toggle="modal"> Counter</a>
    
    ...
    
    <script type="text/javascript">
    document.getElementByid('counterLink').onclick = function () {
        setTimeout(/* ... */, 5000);
    };
    </script>

  3. #3
    Join Date
    Jul 2013
    Posts
    66
    Sorry, I totally forgot that you already seem to be using jQuery. In this case, you can of course use it for attaching the event listener:

    Code:
    $('#counterLink').on('click', function (event) {
        setTimeout(/* ... */, 5000);
    });

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles