user2238083
user2238083

Reputation: 591

Change a value in an img

at the the moment i'm doing this:

 $('.Zoom').empty()
 $('.Zoom').prepend('<img id="zoom_07" src="Zoom.png" data-zoom-image=' + zoomImageDataUri + '/>');

What I want to do is just change the "data-zoom-image=" part. How would I do this, something like:

 document.getElementById("zoom_07")."data-zoom-image=""+ zoomImageDataUri +";

Upvotes: 0

Views: 88

Answers (2)

mpen
mpen

Reputation: 283313

First, you don't have to worry about escaping/building HTML strings if you use jQuery to create the element:

$('.Zoom').empty().prepend($('<img>',{id:'zoom_07', src:'Zoom.png','data-zoom-image':zoomImageDataUri});

Second, I'm not quite sure what you're trying to do with the 2nd bit; your syntax is way off. Try this:

$('#zoom_07').attr('data-zoom-image',zoomImageDataUri);

You may also utilize the $.data method, but I don't think it updates the attribute, just jQuery's internal representation of it.

Upvotes: 2

Ross
Ross

Reputation: 17987

$('#zoom_07').attr('data-zoom-image', zoomImageDataUri);

?

Upvotes: 0

Related Questions