2
I need to implement a rule to allow the badge to change color according to "Value" but the rule is only taking the 1 badge the others are not taking as it should use in my Javascript?
<nav class="tiles box-one mx-auto d-table w-50 ">
    <div type="button" class="btn tile col-md-2 badge  position-relative">
        <img src="./img/logo_meli.jpg">
        <input id="ValBdg" type="hidden" value="1" />
        <span  class="bdg badge position-absolute badge-notification btn-danger"> 666</span>
    </div>
    
    <div type="button" class="btn tile col-md-2 badge position-relative">
        <img src="./img/logo_meli.jpg">
        <input id="ValBdg" type="hidden" value="2" />
        <span  class="bdg badge position-absolute  badge-notification btn-danger"> 666</span>
        
    </div>
    <div type="button" class="btn tile col-md-2 badge  position-relative" >
        <img src="./img/logo_meli.jpg">
        <input id="ValBdg" type="hidden" value="0" />
        <span  class="bdg badge position-absolute  badge-notification btn-danger"> 666</span>
        
    </div>
</nav>
var ValBdg = document.getElementById('ValBdg').value;
function Msg(){
    var nodes = document.getElementsByClassName('bdg');
    for (let x=0, s=nodes.length; x<s; x++){
        nodes[x].classList.add("btn-danger");
    }
}
function NoMsg(){
    var nodes = document.getElementsByClassName('bdg');
    for (let x=0, s=nodes.length; x<s; x++){
        nodes[x].classList.remove("btn-danger");
        nodes[x].classList.add("btn-primary");
    }
}
if(ValBdg > 0 ){
    Msg();
}else{
    NoMsg();
}
so I made here a class called "Valbdg", so I did Document.getElementsByClassName('Valbdg'); but still inside that I need to take the "value", know how to apply this to Function ?
– Maykonctba
I edited the answer and added an example. Please check,
– dfvc
Perfect guy was just what I needed (editing it did not even need to use CSS) thank you very much, I preferred in Javascript that I have more familiarity but I will familiarize myself in Jquery tb. Just one more question in cases where Value came "0" I would like to make the image stay in Grayscale , I found something here just with CSS would not have to do only in JS right.
– Maykonctba
Great. If you solved the problem, please tick this correct answer. I also prefer js vanilla but as its initial code was in jQuery, I answered in jQuery.
– dfvc