简体   繁体   中英

I want to change the color of the first Button, when I clicked on the second

I am very new to coding. I found a inspiration and started making my website. I made a logo and 2 buttons, Shots and Designers. When I click on the first and the second button, they both change their color to white, but thats not what I want. I want that when I click on the second button, the first button change this color to start color (grey).I mean if button 2 clicked, change button 1 color to grey. Here is my code:

 <head>
 <title>Richis corner</title>
 </head>
 <head>
 <style>
 .rectangle {
   height: 85px;
   width: 4500px;
   background-color: #242526;
   margin-top: -43px;
   margin-left: -8px;
}
.image {
  margin-top: -147px;
  margin-left: -50px;
}
.button1 {
  font-family: Helvetica;
  background: none;
  color: grey;
  border: none;
  font-size: 18px;
  outline: none;
}
</style>
</head>
<body>
<div class="rectangle"></div>
<img src=https://i.yapx.ru/Koe4kb.png" class="image">
<button style="margin:-37px -25px;position: absolute;" class="button1" id="demo" onclick="myButton()"> 
Shots</button>
<button style="margin:-37px 50px;position: absolute;" class="button1" id="demo2" 
onclick="mysecondButton()"> Designers</button>
<script>
function myButton() {
  document.getElementById("demo").style.color = "white";
  }
function mysecondButton() {
  document.getElementById("demo2").style.color = "white";
  }
</script>
</body>```



Here is your change

 <script> function myButton() { document.getElementById("demo").style.color = "white"; } function mysecondButton() { document.getElementById("demo").style.color = "grey"; } </script>

function myButton() {
  document.getElementById("demo").style.color = "white";
}
function mysecondButton() {
  document.getElementById("demo").style.color = "grey";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM