I have this part of my site where i'm using javascript to show and hide a div when clicked, so far so good, my problem is i want the color of the button to change when clicked, so that the color in ".steg1" changes to #CCA200 when i click ".steg2".
I have tried focus, but I have more places on the same page where I need to use this so I'm looking for a different solution. I've tried some jquery with no luck, is this doable in javascript?
here is the code:
<button class="steg1" onclick="myFunctionq();">
1 - TECKNA MOBILABONNEMANG
</button>
<style>
.steg1 {
font-family: 'mark-heavy';
font-size: 16px;
background-color: transparent;
border: none;
border-bottom: solid 5px;
color: #223137;
padding: 0 40px;
}
</style>
<script>
function myFunctionq() {
var x =
document.getElementById("tecknamobil");
var y =
document.getElementById("tecknael");
var z =
document.getElementById("rabatt");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
y.style.display = "none";
z.style.display = "none";
}
</script>
<button class="steg2" onclick="myFunctionp()">
2 - TECKNA ELAVTAL
</button>
<style>
.steg2 {
font-family: 'mark-heavy';
font-size: 16px;
background-color: transparent;
border: none;
border-bottom: solid 5px;
padding: 0 60px;
color: #CCA200;
}
</style>
<script>
function myFunctionp() {
var x =
document.getElementById("tecknael");
var y =
document.getElementById("tecknamobil");
var z =
document.getElementById("rabatt");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
y.style.display = "none";
z.style.display = "none";
}
</script>
<button class="steg3" onclick="myFunctionr(); buttonColorb()">
3 - FÅ RABATT PÅ ELEN
</button>
<style>
.steg3 {
font-family: 'mark-heavy';
font-size: 16px;
background-color: transparent;
border: none;
border-bottom: solid 5px;
padding: 0 50px;
color: #CCA200;
}
</style>
<script>
function myFunctionr() {
var x =
document.getElementById("rabatt");
var y =
document.getElementById("tecknael");
var z =
document.getElementById("tecknamobil");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
y.style.display = "none";
z.style.display = "none";
}
</script>
Ok, i've gotten it to work to almost perfection, I only need to when step1 is pressed after the other steps, it stays black, how do i put so that "if this is .focused then it should be .colored? here is the updated code.
<button id="step1button" class="step1" onclick="step1Click();">
1 - TECKNA MOBILABONNEMANG
</button>
<style>
#step1button {
font-family:'mark-heavy';
font-size:16px;
background-color:transparent;
border:none;
border-bottom:solid 5px;
color:#223137;
padding: 0 40px;
}
</style>
<script>
function step1Click() {
var x =
document.getElementById("tecknamobil");
var y =
document.getElementById("tecknael");
var z =
document.getElementById("rabatt");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
y.style.display = "none";
z.style.display = "none";
document.getElementById('step1button').classList.add('focused');
document.getElementById('step3button').classList.remove('focused');
document.getElementById('step2button').classList.remove('focused');
}
</script>
<button id="step2button" class="step2" onclick="step2Click()">
2 - TECKNA ELAVTAL
</button>
<style>
#step2button {
font-family:'mark-heavy';
font-size:16px;
background-color:transparent;
border:none;
border-bottom: solid 5px;
padding:0 60px;
color:#CCA200;
}
</style>
<script>
function step2Click() {
var x =
document.getElementById("tecknael");
var y =
document.getElementById("tecknamobil");
var z =
document.getElementById("rabatt");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
y.style.display = "none";
z.style.display = "none";
document.getElementById('step1button').classList.add('colored');
document.getElementById('step3button').classList.remove('focused');
document.getElementById('step2button').classList.add('focused');
}
</script>
<button id="step3button" class="step3" onclick="step3Click(); colorchange()">
3 - FÅ RABATT PÅ ELEN
</button>
<style>
#step3button {
font-family:'mark-heavy';
font-size:16px;
background-color:transparent;
border:none;
border-bottom: solid 5px;
padding: 0 50px;
color:#CCA200;
}
.colored {
color:#CCA200 !important;
}
.focused {
color:#223137 !important;
}
</style>
<script>
function step3Click() {
var x =
document.getElementById("rabatt");
var y =
document.getElementById("tecknael");
var z =
document.getElementById("tecknamobil");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
y.style.display = "none";
z.style.display = "none";
document.getElementById('step1button').classList.add('colored');
document.getElementById('step3button').classList.add('focused');
document.getElementById('step2button').classList.remove('focused');
}
</script>