locked
Retrieving src from dynamicaly created images RRS feed

  • Question

  • User-257070954 posted

    How can i retrieve src from  dynamically created image. Below giving my code

    Creating  image

    var ProductHtml +="<div id=divParenList" + value.Id + ">
                       + "<img id=Image" + value.Id + " class=form-group src=data:image/jpeg;base64," + value.Image + " width='100%' height=200 />"
             </div>

    Retrieving  Code

    function RetrieveImage(id) {
    alert('for relative image url ' + $('#Image' + id).attr('src')); // Here i am getting Undefined
    }

    Monday, June 29, 2020 11:51 AM

All replies

  • User475983607 posted

    I assume the selector is not finding an img element.   The attribute values are missing quotes which is a problem.  Other than that, the dynamic HTML code could have a runtime bug or calling the RetriveImage(id) function could have a bug.  

    First, fix the HTML and retry.  Learn how to use the browser's dev tools to find JavaScript/jQuery bugs. 

    Monday, June 29, 2020 12:34 PM