Reputation: 431
I want to hide the previous logo and menu bar but when I click the menu bar. But the result is not expect.
HTML:
<div class="header">
<img src="common/img/logo.png" class="logo">
<input type="checkbox" id="chk">
<label for="chk" class="show-menu-btn" onclick="myChk()">
<i class="fas fa-bars"></i>
</label>
<label for="chk" class="hide-menu-btn">
<i class="fas fa-times"></i>
</label>
Script:
function myChk(){
var image = document.getElementById("show-menu-btn");
if(image.src.match("show-menu-btn")){
image.src = "none";
}else{
image.src = "common/img/logo.png";
}
}
Upvotes: 0
Views: 360
Reputation: 647
Instead of changing src, you can do image.style.diplay = 'none' for hiding and image.style.diplay = 'inline-block' for showing.
HTML
<div class="header">
<img src="common/img/logo.png" class="logo" id="logo">
<input type="checkbox" id="chk">
<label for="chk" class="show-menu-btn" onclick="myChk()">
<i class="fas fa-bars"></i>
</label>
<label for="chk" class="hide-menu-btn">
<i class="fas fa-times"></i>
</label>
</div>
JS:
function myChk(){
var image = document.getElementById("logo");
if(image.style.display === 'none'){
image.style.display = "inline-block";
}else{
image.style.display = "none";
}
}
Upvotes: 1