JavaScript/Changing elements/Exercises

Topic: Change element's content and attributes

We use the HTML page of the previous page for the exercises.



1. Modify the function show in a way that it disables the button. Its text shall change to "I'm disabled". Hint: To disable a button, its attribute disabled must be set to true.

Click to see solution
function show() {
  "use strict";
  const elem = document.getElementById("buttonShow");
  elem.disabled = true;
  elem.innerHTML = "I'm disabled";
}



2. Modify the function show in a way that it opens the link in a new window: target="_blank".

Click to see solution
function show() {
  "use strict";
  const elem = document.getElementById("refToSomewhere");
  elem.target = "_blank";
}