joao_c
asked on
Jquery add function result to all table rows
Hello Experts.
I need to add thousand separator to each table row, I made a simple example to illustrate the issue.
The problem here is that the function replaces all the tr's with the first value, what am I doing wrong?
I need to add thousand separator to each table row, I made a simple example to illustrate the issue.
The problem here is that the function replaces all the tr's with the first value, what am I doing wrong?
<html>
<head>
<title>test milhares</title>
<script src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
function numberWithSeparation(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
}
$(document).ready(function() {
var trs = $('tr.ai');
trs.html( numberWithSeparation(trs.html()) );
});
</script>
</head>
<body>
<table border=1>
<tr class='ai'><td>50000</td></tr>
<tr class='ai'><td>80001</td></tr>
</table>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER