Link to home
Start Free TrialLog in
Avatar of joao_c
joao_cFlag for Portugal

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?

<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>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of joao_c

ASKER

Perfect. Thanks a lot.