Closed Amirsohal closed 7 years ago
You need to use the "destroy" method before changing the image src and then attach the widget to the new image as shown below:
<img id="image" src="images/test_image.jpg" width="80%" /><br/>
...
<script type="text/javascript">
...
var $img = $("#image").imgNotes();
...
var $toggleI = $("#toggleImage");
$toggleI.on("click", function() {
$img.imgNotes("destroy");
var src = ($("#image").attr('src') === 'images/test_image.jpg')
? 'images/test_image_2.jpg'
: 'images/test_image.jpg';
$("#image").attr('src',src);
$img = $("#image").imgNotes({ onEdit: cust_onEdit });
});
...
</script>
@waynegm Thanks for you reply +1:
As per my requirement I need to change the image, so I am changing the src of the same img tag (i.e. 'img01') and calling the $img = $("#img01").imgNotes(); method every time when src of img tag is changed but its calling _create function of imgNotes some times but not every time. Is there any issue to call this method multiple times? Before calling imgNotes() I am removing the viewport class by using $('.viewport').remove() method. Please suggest me if I am doing anything in wrong way.