javascript - changing the img src with jquery -


the html structure have like:

<ul id="something">   <li>     <a href="">       <img src="http://domain.com/directory/file1-128x79.jpg">     </a>   </li>   <li>     <a href="">       <img src="http://domain.com/directory/file2-128x79.jpg">     </a>   </li>   <li>     <a href="">       <img src="http://domain.com/directory/file3-128x79.jpg">     </a>   </li> </ul> 

i'm trying change filename file#-128x79.jpg file#-896x277.jpg.

i don't know how take dynamically generated filename , search , replace src changes.

i found way replacing whole src 'none' make sure got right far, don't know how rest.

$('#something').removeattr('id').prop('class', 'some-class').find('img').prop('src', 'none'); 

you can replace src each img first selecting images selector , using attr callback replace contents:

$('#something img').attr('src',function(i,e){     return e.replace("-128x79.jpg","-896x277.jpg"); }) 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -