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&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
Post a Comment