how to hide class with javascript . I get a value if status = 1 then the class show, and if status = 2 then the class is hidden.
<div class="entry-img" id="status">
<img id="txt_img_content_1" alt="" class="img-fluid">
</div>
how to hide class with javascript . I get a value if status = 1 then the class show, and if status = 2 then the class is hidden.
<div class="entry-img" id="status">
<img id="txt_img_content_1" alt="" class="img-fluid">
</div>
I thing, that toggle might be to use in your case:
function setStatus(status) {
document.querySelector("#status").classList.toggle("entry-img", status == 1);
}
div {
width: 30px;
height: 30px;
background: #f00;
border-radius: 100%;
}
.entry-img {
background: #0f0;
}
<div id="status"></div>
<button onclick="setStatus(1)">1</button>
<button onclick="setStatus(2)">2</button>
You can do it with the code something like this.
var element = document.getElementById("status");
if(status==2){
element.classList.remove("entry-img");
}
if(status==1){
element.classList.add("entry-img");
}
For more information you can refer to this links https://www.w3schools.com/howto/howto_js_remove_class.asp https://www.w3schools.com/howto/howto_js_add_class.asp https://www.w3schools.com/js/js_if_else.asp
var divElement = document.getElementById("status");
if(status==2){
divElement.classList.remove("entry-img");
}
if(status==1){
divElement.classList.add("entry-img");
}