I have a lightbox gallery.

<ul class="gallery"> <li><a href="http://newdomain.ru/images/30652.jpg" title="" rel="lightbox-atomium"> <img src="http://newdomain.ru/images/30652t.jpg"> </a> </li> </ul> 

It is necessary when a link to a large picture is lost, replace its address from the old domain. I am writing on jQuery - does not work. What am I doing wrong

 <script> $('a').on('error',function(){ $(this).attr('href', $(this).attr('href').replace('newdomain', 'olddomain')); }); </script> 

    1 answer 1

    What do you think, at what point should the error event occur on element а ?

     $(".gallery li a").each(function(i, a) { var img = document.createElement("img"); img.onerror = function() { $(a).attr('href', $(a).attr('href').replace('newdomain', 'olddomain')); }; img.style.display = "none"; img.src = $(a).attr('href'); a.appendChild(img); });