Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to show a button after one of the two buttons are clicked?

I want two buttons to appear right after one of the two buttons prior is pressed.

var a = "Jeg heter ";
var b = "Benjamin";
var j = "Jasmin";

function endre() {
  var x = document.getElementById("endre1");
  if (x.innerHTML == "Velg navn" || j) {
      x.innerHTML = a + b;
  }
}

function endre2() {
  var x = document.getElementById("endre1");
  if (x.innerHTML == "Velg navn" || b) {
      x.innerHTML = a + j;
   }
}
<button onclick="endre2()">Jasmin</button>
<button onclick="endre()">Benjamin</button>
<div id="endre1">Velg navn</div>
<br>
<button class="visknapp24()" style="display: none;">24 år</button>
<button class="visknapp20()" style="display: none;">20 år</button>

Any way to add to this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Firstly you need the same function to show for both the buttons. Also, you have to just query the buttons using either querySelector() or getElementsByClassName().

Once you have that you can use style property from JS to modify CSS styles:

var a = "Jeg heter ";
    var b = "Benjamin";
    var j = "Jasmin";

    function endre() {
    var x = document.querySelector(".visknapp24");
    var y = document.querySelector(".visknapp20");
   x.style.display = 'block';
   y.style.display = 'block';
   
}
<button onclick="endre()">Jasmin</button>
<button onclick="endre()">Benjamin</button>
<div id="endre1">Velg navn</div>
<br>
<button class="visknapp24" style="display: none;">24 år</button>
<button class="visknapp20" style="display: none;">20 år</button>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading