How do I change the counter value?

  • 0
    Good day, tell me how you can change the counter value when there is only access to adding custom CSS and JS in the store.
    Two values ​​need to be changed separately 58/400
    Let's add 20 to 58
    Where 400 take away 200

    JavaScript Hazel Robertson, Nov 13, 2019

  • 2 Answers
  • 0
    // Найти уникальный селектор для искомого элемента
    var elem = document.querySelector('div.xserver__status');
    // спарсить значения
    let [a, b] = elem.innerText.split(/\D*\/\D*/).map(Number);
    // вернуть новые
    elem.innerText = `${a + 20} / ${b - 200}`;
    Caroline Singh

  • 0
    var text = document.querySelector('.xserver__status').innerText;
    var arr = text.split(' / ');
    arr[0] = parseInt(arr[0]) + 20;
    arr[1] = parseInt(arr[1]) - 200;
    document.querySelector('.xserver__status').innerText = arr.join(' / ');
    Harrison Burgess

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!