Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery .replace(/./g, "") do not work for me but others

I found this snippet somewhere and it works like a charm:

var n = parseInt(e.find("span.favNum").text().replace(/./g, "")) + 1;

If I do it in a similar way it doesn't work anymore.

I do the following:

<div id ="test">6.987</div>
var test = $("#test");
var r = test.text().replace(/./g, "");
console.log("wrong ", r);

I know that I can replace it also like this:

var r = test.text().replace(".", "");

This works.

I would like to understand why the "stolen" snippet is working. Any idea?

http://jsfiddle.net/nJZMf/3/

The original script is found here: http://wp-svbtle.themeskult.com/

You will find the snippet by viewing the source of index.html and searching for .replace.

like image 883
hamburger Avatar asked Jun 06 '13 19:06

hamburger


1 Answers

You need to escape the "."

test.text().replace(/\./g, "");
like image 71
pvnarula Avatar answered Oct 01 '22 22:10

pvnarula