1
document.getElementById("RightButton").innerHTML="Back to Question";
document.getElementById("RightButton").onclick=GoBack();

Is the code I wrote to solve my problem. The first line successful changed the name of the button, but the second line simply doesn't work.

As you may have discovered, I'm totally a newbie. If you use excessive jargon, it will probably take me another question to figure out the jargon.

3 Answers 3

4

Just remove the (). That way, you pass the function itself rather than calling it.

Sign up to request clarification or add additional context in comments.

Comments

2

GoBack is a function. Assign the function reference to the onclick property, but don't execute it immidiately with (). That way you assign the result of the call as the handler, not the function-to-be-executed when the element is clicked. Read more on event registration here.

var button = document.getElementById("RightButton");
button.innerHTML = "Back to Question";
button.onclick = GoBack;

As a note, conventionally only constructor functions use uppercase letters.

Comments

0

You are calling the GoBack() function instead of assigning it to to the onclick event. Change your code to the below and you should be all set.

document.getElementById("RightButton").onclick=GoBack;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.