Get just numbers from a list Content HTML

45 Views Asked by At

Currently I am starting a Project in Javascript its a Game cards, I wanna get just the numbers from the list no string just Ints numbers text

enter image description here

I want to take just numbers from a list HTMl no string. I try to convert to parseInt but I know when get the element return as array just with the quantity of class I do not have the content

power = document.getElementsByClassName("power").innerText;
let opNum0 = parseInt(document.getElementsByClassName("power")[0].innerText);
let myNum3 = parseInt(document.getElementsByClassName("power")[3].innerText);
console.log(myNum3);

if (myNum3 > opNum0) {
  alert("you win");

} else {

  alert(myNum3);
  scoreCountYou()

}

1

There are 1 best solutions below

0
Hassan Safari On BEST ANSWER

try this

let opNum0 = parseInt(document.getElementsByClassName("power")[0].innerText.replace(/\D/g,''));
let myNum3 = parseInt(document.getElementsByClassName("power")[3].innerText.replace(/\D/g,''));
console.log(myNum3);

if(myNum3 > opNum0){
    alert("you win");
}else{
    alert(myNum3);
    scoreCountYou()
}