Showing results for 
Show  only  | Search instead for 
Did you mean: 
New Member

No longer able to hide the Next button?

Hi everyone,

Last summer, I was able to successfully implement code which hid the 'Next' button until a certain event happened (eg, after a student clicked x times, the 'Next' button would reappear).

The code looked for the 'Next' button several times and, if it was there, it would remove it. After the student completed the task, a new function would be called to show the 'Next' button again.

Here's a snippet of the code to hide the button:

var btn = document.createElement("BUTTON");
var $nextButton = {};
$nextButton = $('.module-sequence-footer-button--next');
var checksMax = 100;
var checkCurr = 0;

function hideNext(checkCurr) {
   console.log('Checked for the next button ' + checkCurr + ' times.');
   $nextButton = $('.module-sequence-footer-button--next');

   if ($nextButton.length < 1 && checkCurr < checksMax) {
      setTimeout(function () {
      hideNext(checkCurr + 1);
}, 100);

console.log("hideNext was called")

Now, the 'Next' button is no longer being hidden even though hideNext is consistently called. The console states "Checked for the next button undefined times", so checkCurr is undefined for some reason.

I'm not sure what's going wrong this time around. Help would be appreciated if anyone knows how I can get the 'Next' button successfully hidden again. Thanks for reading!

1 Reply
Community Champion


I‘m not a JavaScript developer but was curious if you set the var using new might help.

var checkCurr = new Number(1);‍‍‍‍

Additionally, have you considered adding in a conditional to check typeof within the function?