Abdul M. Diaz Abdul M. Diaz - 5 months ago 9
jQuery Question

Button onclick won't work

On my site, when I click the "Begin the Exam" button, some elements are supposed to be shown. However, whenever I click it, the elements are shown and then hidden. This is the site and this is the code that controls the

onclick()
event :

// Display initial question
$("#begin").click(function(){
$("#quiz").removeClass("hidden");
$("#intro").addClass("hidden");
$("#prev").removeClass("hidden");
$("#next").removeClass("hidden");
$("#questionnum").removeClass("hidden");

displayNext();
});

Answer

You can solve this as follows;

$("#begin").click(function(event){
  event.preventDefault();

  $("#quiz, #prev, #next, #questionnum").removeClass("hidden");
  $("#intro").addClass("hidden");

  displayNext();
});

Or, just you can modify your "Begin the exam" button for solving this. If you update href attribute like this; href="javascript:;", you can solve this. Because, when your has empty href attribute, page will be refreshed. You need to prevent this default action or you need to set an useless href attribute to your link.