user1996496 user1996496 - 12 days ago 6
Javascript Question

disabling onclick with jQuery until page is loaded?

I have a button that works

onclick
. The problem is that it fails to work if the page is not fully loaded, so I want to disable it until the page is loaded and then enable it with jQuery.

<div class="btn btn-block" onclick="launchAction()">
<div class="launch"><i class="icon-launch"></i></div>
Launch
</div>


How would I do that? I tried to
disable
it but that didn't stop onclick from working.

Answer

Do the following:

<div class="btn btn-block" id="mybutton">
<div class="launch"><i class="icon-launch"></i></div>
Launch
</div>

<script>
  $(document).ready(function() {
    $("#mybutton").click(function () {
      launchAction();
    });
  });
</script>
Comments