adikitty CB
adikitty CB

Reputation: 57

Get Image source by dynamically generated tag

I have span tag inside of that tag, new image tag is dynamically generated but I need to get that image src of that tag is it possible

<span id ="Imagespan">
    <image scr="some.png" alt="some" />
<span>  

Upvotes: 0

Views: 205

Answers (2)

l.hussain
l.hussain

Reputation: 472

You mean img instead of image, yes you can, try :

$('#Imagespan').find('img').attr('src');
//or also
$('#Imagespan').find('img').prop('src');

Or use direct selector like :

$('#Imagespan img').prop('src');

Note: doesn't matter if the element is dynamically created or not, the method of getting the 'attribute/property' is the same.

.attr() changes attributes for that HTML tag.

.prop() changes properties for that HTML tag as per the DOM tree.

As the example in this link suggests. An input field can have the attribute "value". This will equal the default value you entered. If the user changes the value in the input field, the property "value" changes in the DOM Tree, but the original attribute is left remaining.

Source

Upvotes: 1

ravi kanth
ravi kanth

Reputation: 36

If you are using jquery then the below code gives you the source of dynamically created image

jQuery('#Imagespan img').attr('src')

Upvotes: 0

Related Questions