how to disable a html button after it has been clicked not a submit button

Pazrat picture Pazrat · Sep 26, 2013 · Viewed 27.7k times · Source

hi i have a html button and when you press it, it should give you the distances of shops from where you are so when you press it they appear now the problem is because it is in early stages the information is printed everytime the button is pressed i would just like to now how to disable it when it has been pressed once and then reactivate it when another button has been pressed this is not a submit button my code for the button is :

   <button onclick="getLocation()">Search</button>

any help would be much appreciated thanks in advance

Answer

Sasidharan picture Sasidharan · Sep 26, 2013

I think its very clear for you..

Call your getlocation() method inside the click event..

Working fiddle

Code

$( "#bind" ).click(function() {
   $(this).attr("disabled", "disabled");
   $("#unbind").removeAttr("disabled");
});
$( "#unbind" ).click(function() {
     $(this).attr("disabled", "disabled");
     $("#bind").removeAttr("disabled");
});

Output

Result