I'm trying to replace a string which is created by a getJSON call.
I tried several things inside document ready
to replace everything before the :
.
Nothing seems to work. Can somebody point me on what I'm doing wrong?
If I use replace
outside the getJSON then replace should work, right?
$(document).ready(function(){
$.getJSON('url?format=json', function(data){
var variants = [];
$.each(data.product.variants, function(index, variant){
variants.push('<li>'+variant.title+'</li>');
// response is something like "SIZE: XS" or
// "SIZE: XL" etc...
});
variants = variants.join('');
$('.size_123').html('<ul>'+variants+'</ul>');
});
$(".size_123").html(function(index, currentHtml) {
return currentHtml.replace(/\SIZE/gi, " ");
});
// I also tried this inside the getJSON function.
// variantTitle = variant.title;
// variantClean = variantClean.substr(variantTitle.lastIndexOf(":") + 1);
});