user1072910 user1072910 - 1 year ago 63
Javascript Question

Evaluating the src attribute in a HTML image tag

I'm going in circles on this one and am hoping you can help.

In my HTML file I have an image tag generated by a third-party plugin that looks like this:

<p><img alt="{x_{3}}^{4}" src="" /></p>

I would like to be able to do away with the reference to and instead have the src point to the data itself. Something like...

<p><img alt="{x_{3}}^{4}" src="data:image/png;base64, ..." /></p>

How would I go about this in jquery?



Answer Source

I guess this example will help you

but in your case instead of:

var imageUrl = $(this).find('[name=url]').val();

add the following line

var imageUrl = $(this).find('img').attr('src');

something like that should do it for you.

PS: I don't own the fiddle I just found it online


Here's a version with a fix for the CORS problem

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download