Do this <button>, which has an event onclickassociated with it that executes an AJAX request to send a request to someone with a page handler that will update the database or similar, and upon successful completion, change its CSS style to make it look clicked.
Use jQuery to bind events AJAX request , and CSS class change , and this style should work, make the button pressed.
<button type="button" id="btnPlay">Play</button>
Then:
$("#btnPlay").click(function(){
var button = $(this) ;
if (!button.hasClass('pressed')) {
$.post("ajax.php", { userId: "5512", action: "play" },
function(data){
button.addClass('pressed');
button.html("Playing!") ;
}
);
}
else {
$.post("ajax.php", { userId: "5512", action: "stopPlaying" },
function(data){
button.removeClass('pressed');
button.html("Play") ;
}
);
}
});
Fanis source
share