Reputation: 2528
Morning,
I need to replace some characters in jQuery with different characters due to the way images are displayed on the site. I need to replace the & and the / with an _
I currently have, how would i do the / ?
$('#lnkProdImage').attr("href", "http://img.website.com/500/" + res.sku.replace(/&/g, '_').replace(/[\s]/g, '_') + ".jpg");
Many thanks in advance.
Upvotes: 0
Views: 129
Reputation: 174937
Seriously?
$('#lnkProdImage').attr("href", "http://img.website.com/500/" + res.sku.replace(/[&\s\/]/g, '_') + ".jpg");
Why the 3 replaces? Could be done in a single one!
Upvotes: 1
Reputation: 307
$('#lnkProdImage').attr("href", "http://img.website.com/500/" + res.sku.replace(/&/g, '_').replace(/[\s]/g, '_').replace(/\//g, '_') + ".jpg");
Upvotes: 0