Solution 1 :

The numeric value of strings such as "1k" or "1m" is NaN.

Therefore, you may use Number.isNaN method to determine whether the string should be updated.
for example:

function increase (elem) {
    var previousValue = Number(elem.text());
    if (!Number.isNaN(previousValue)) {
        elem.text(previousValue + 1);
    }
}

increase($('.num_1'))

Problem :

I have an updateable list

<ul>
  <li>
    <a class="one">posts <span class="num_1">1</span></a>
    <a class="two">followers <span class="num_2">999</span></a>
    <a class="three">following <span class="num_3">1K</span></a>
  </li>
</ul>

<button class="post-btn">Post</button>
<button class="follow-btn">Follow</button>

if a user updates the list by clicking either button and the number is below 1000, i want to get the text and add or subtract 1. if the number is above 1000, hence 1K, i want nothing to happen. all i have so far is this code which works for numbers under 1000 and not numbers abbbreviated as 1K

$('.num_1').text(Number($('.num_1').text())+1); or $('.num_1').text(Number($('.num_1').text())-1);

any help would be appreciated thanks

Comments

Comment posted by Mamun

if the number is above 1000, hence 1K, i want nothing to happen. all i have so far is this code which works for numbers under 1000 and not numbers abbbreviated as 1K?

Comment posted by Check if string contains only digits

Does this answer your question?

Comment posted by s.kuznetsov

you will also need to multiply the number by 1000, if there is a

Comment posted by Carsten Massmann

Translating the postfixes

Comment posted by Max Njoroge

@freedomn-m yes thanks that helps

Comment posted by Max Njoroge

decided to just update with AJAX instead, thank you

By