andrelange91 andrelange91 - 3 months ago 42
jQuery Question

add to src in img with jquery

i need to change this :

<img src="example.jpg" alt="">

into this:

<img src="example.jpg?width=500" alt="">

with jquery, how can this be achived, because i don't want to overwrite the src,
but just add that ?width=500 bit.

my code looks something like this in total:

<div class="img-wrap">
<p><a href="link">Link to something</a></p>

<img src="example.jpg" alt="">


Okey, im sorry i did not specify, but i cannot make any changes to the img tag.
The image is generated from the backend. the div, is the only thing i have any sort of power over.


Try this

  $(".img-wrap p img")[0].src += "?width=500";

<div class="img-wrap">
  <p><a href="link">Link to something</a>
  <img src="example.jpg" alt="">