Ole Albers
Ole Albers

Reputation: 9285

src of dynamicly generated image is undefined

I have an HTML block I create dynamically. I cannot get the src property of an image inside this block.

The following are the properties from the Chrome developer console:

typeof(image)
"object"

image.html()
"<img src="../images/icons/quickshare/enabled/accounting/abacus_48.png">"

image.src
undefined

image.attr("src")
undefined

image.prop("src")
undefined

As you can see, the HTML of the image object has the correct content, but I cannot access the src property. What could be the cause?

Upvotes: 0

Views: 249

Answers (1)

adeneo
adeneo

Reputation: 318182

If that's the HTML (html() returns innerHTML), you currently have the parent element of the image

try

image.find('img').prop('src')

Upvotes: 5

Related Questions