I have made some code (with a lot of help from you guys), and was wondering if there is any way to make the JavaScript work with a certain letter instead of numbers.
let boxes = document.getElementsByClassName("centerbox")
for (let i = 0; i < boxes.length; i++) {
let box = boxes.item(i)
let content = box.getElementsByTagName("p")[0].innerHTML
let number = Number(content)
if (number <= 0) {
box.classList.add("red");
}
else if (number >= 1 && number < 5) {
box.classList.add("yellow");
}
else if (number >= 5) {
box.classList.add("green");
}
}
.centerbox::before {
content: "";
display: inline-block;
width: 10px;
height: 10px;
border-radius: 50%;
}
.green::before {
background-color: green;
}
.red::before {
background-color: red;
}
.yellow::before {
background-color: yellow;
}
.pstyle {
display: inline-block;
margin-left: 0px;
}
.widthcontainer {
width: 100%;
height: auto;
background-color: red;
}
<div class="centerbox">
<span class="">En el almacén |</span>
<p class="pstyle">0</p>
</div>
I want the code to work the same way as it does now, but if the <p>
has a certain letter “f”, I would like it to write me a string.
Is there a way to do this? I was thinking somthing like converting the string, but I can’t really seem to make it work.
`?
– Sebastian Simon Aug 29 '18 at 10:43