andrelange91 andrelange91 - 1 year ago 97
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.

Answer Source

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="">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download