regex - jQuery remove all characters after ? in img src -


would modify img src from:

<div class="solo">   <img src="/uploads/2016/08/simone-b.jpg?fit=97%2c146&amp;ssl=1"> </div> 

to:

<div class="solo">   <img src="/uploads/2016/08/simone-b.jpg"> </div> 

tried using following not working:

jquery('.solo img').each(function(){      jquery(this).attr('src',jquery(this).attr('src').replace('?*','')); }); 

any suggestions? in advance

in code .replace('?*','') replace string ?*. removing particular part need use regex instead .replace(/\?.*/,'').

but better way use attr() method callback iterate , update based on old value. can use string#split method removing string part after ? in attribute value.

jquery('.solo img').attr('src',function(i,v){    return v.split('?')[0]; // string part before `?`    // or     // return v.replace(/\?.*/,''); }); 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -