Reputation: 266
I'm having trouble getting the replace function to work. Here's my code:
var divid = $(this).parents(".list-radio").attr('id').match(/\d/g);
divid = divid.replace(/\,/g,"");
The first line brings back a set of digits separated by commas (e.g. "2,2,3") and I was hoping the second line would remove the commas, but it just fails.
Any ideas?
Thanks in advance,
Ash
Upvotes: 0
Views: 71
Reputation: 129792
No, the .match
gives you an array of digits, without commas. If you alert
the array or try to turn it into a text representation by some other means, it may show up as a comma spearated list, but that's just a presentational artefact.
If you want the result as a string of digits without commas you may run divid.join('')
. Another way would be to just remove anything that isn't a digit from the original string:
var divid = $(this).parents(".list-radio").attr('id').replace(/\D/g,'');
Upvotes: 4