javascript - Change a value in an img -


at the moment i'm doing this:

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

what want change "data-zoom-image=" part. how this, like:

 document.getelementbyid("zoom_07")."data-zoom-image=""+ zoomimagedatauri +"; 

first, don't have worry escaping/building html strings if use jquery create element:

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

second, i'm not quite sure you're trying 2nd bit; syntax way off. try this:

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

you may utilize $.data method, don't think updates attribute, jquery's internal representation of it.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -