javascript - Change value of element inside img tag in JS -
i have html fragment display product image:
<img src="/some/path" border="0" id="bigimg" data-zoom-image="/some/path"> the code data-zoom-image path larger image on mouse over, can zoom in on image.
i have javascript function when click somewhere else change picture... this:
function showlarge(path) { var full_path = 'upload/product_image/large_'+path; document.getelementbyid("bigimg").src = full_path; document.getelementbyid("bigimg").data-zoom-image = full_path; } i want change data-zoom-image value when src of image changes... tried adding line document.getelementbyid("bigimg").data-zoom-image = full_path; doesn't work... how should this...
thank you
you can use setattribute changes value of existing attribute on specified element.
document.getelementbyid("bigimg").setattribute('data-zoom-image',full_path); the document here:
https://developer.mozilla.org/en-us/docs/web/api/element.setattribute
Comments
Post a Comment