BalajiB BalajiB - 3 months ago 8
jQuery Question

Find the 'source' value of image (img) where its Id is dynamically changing

Here is the code

<img id="simple_captcha-ad089ff4819" src="/simple_captcha?code=a35401d">`


In this,
img
tag's
id
is not static. It keeps on changing for every new action.

For the next action, its
id
can be "simple_captcha-sfw454sdfs".
So, based on these id, I have to fetch its
src
value.

Answer

You can use a selector that matches the beginning of the ID.

var src = $("img[id^=simple_captcha-]").attr('src');