0

I want the green ones to change to blue and green , and the Hi to change to Hello. Can somebody tell me in an easy html way how to edit the style and the written things with a button.

function functionl {
  alert('success')
}
.L1 {
  padding: 0px;
  border: 1px;
  border-radius: 200% 0px 200% 0px;
  border-color: green;
  background-color: green;
  font-size: 50px;
  color: white;
  width: 50%;
  height: 47%;
}

.L2 {
  padding: 0px;
  border: 1px;
  border-radius: 0px 200% 0px 200%;
  border-color: green;
  background-color: green;
  font-size: 50px;
  color: white;
  width: 50%;
  height: 47%;
}

.button1 {
  height=5%;
  font-size: 35;
  background-color: Red;
  color: blue;
  border-radius: 30px 30px 30px 30px;
}
<button class="L2">Hi</button><button class="L1">Hi</button><br>
<button class="L1">Hi</button><button class="L2">Hi</button>
<center><button class="button1" onclick="functionl()">Click me</button></center>

I want somebody to show me how to edit my code and how to edit any style from a button

1 Answers1

0

I believe this is what you are looking for:

function functionl() {
  for (let e of document.querySelectorAll('.L1, .L2')) {
    if (e.innerText == 'Hi') {
      e.style.backgroundColor = 'blue';
      e.innerText = 'Hello';
    } else {
      e.style.backgroundColor = 'green';
      e.innerText = 'Hi';
    }
  }
}
.L1 {
  padding: 0px;
  border: 1px;
  border-radius: 200% 0px 200% 0px;
  border-color: green;
  background-color: green;
  font-size: 50px;
  color: white;
  width: 50%;
  height: 47%;
}

.L2 {
  padding: 0px;
  border: 1px;
  border-radius: 0px 200% 0px 200%;
  border-color: blue;
  background-color: blue;
  font-size: 50px;
  color: white;
  width: 50%;
  height: 47%;
}

.button1 {
  height=5%;
  font-size: 35;
  background-color: Red;
  color: blue;
  border-radius: 30px 30px 30px 30px;
}
<body>
  <button class="L2">Hello</button><button class="L1">Hi</button><br>
  <button class="L1">Hi</button><button class="L2">Hello</button>
  <center><button class="button1" onclick="functionl()">Click me</button></center>
</body>
wizzwizz4
  • 6,140
  • 2
  • 26
  • 62
Miroslav Glamuzina
  • 4,472
  • 2
  • 19
  • 33