2
There is a problem, when picking a number within a span by javascript I try to convert it into int with parseint, but nothing. For if I try to make a sum with another number it ends up concatenated. and if I convert with parseint it appears 'NAN'.
HTML:
<div id="qualquer"><span>5</span></div>
Javascript com Jquery:
numeroRecuperado = parseInt($('#qualquer span').text().replace(/[\d]/g, ''));
numeroQualquer = 5;
total = numeroRecuperado + numeroQualquer;
$("#qualquer span").text(total);
As a result it appears NAN.
Add the code you already have to the question.
– Jéf Bueno
Don’t have any space in the string you’re trying to convert to integer? Maybe call the function. Trim() in variable containing span content resolves.
– Ricardo Rodrigues de Faria
Possible duplicate of How I make a whole division?
– gustavox
Nothing to do, it’s not duplicated! Guys I put the code
– Romario Pires
@Romariopires give a
console.log(numeroRecuperado)
and tell us what was shown in console.– Jéf Bueno
Your code is wrong. Your code takes out all the numbers and leaves only what is not number in the text
– Wallace Maxters