In html, the wrong path to the picture. The point is to change the alt attribute 3 seconds after loading. But the timer does not work wherever I insert it

$('img').ready(function(){ $("img").delay(3000).attr('alt','Картинка загружена'); }); `<img src="https://i.pinimg.com/236x/96/ed/20/96ed206c3206f0cfb9a3abae7660873.jpg" alt="Картинка не загружена">` 

    2 answers 2

    In jQuery, .delay() only affects an animation or .queue() . As an option, you can add an attribute change inside the queue .

     $('img').ready(function() { $("img").delay(3000).queue(function(next) { $(this).attr('alt', 'Картинка загружена'); next(); }) }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <img src="https://i.pinimg.com/236x/96/ed/20/96ed206c3206f0cfb9a3abae7660873.jpg" alt="Картинка не загружена"> 

    • And finally, if the picture is loaded ... alt not visible! - user33274
    • @ MaksimLensky, in theory, yes, but apparently the default is “the picture is not loaded”, and under each picture its text seems to be similar to a reasonable explanation, he did something like this - Sergey Glazirin
    • hmm .... interesting ... what only tasks happen ...) - user33274

    Use setTimeout() if you just want to trigger an action after a certain time:

     $(document).ready(function () { $('img').ready(function () { setTimeout(function () { $("img").attr('alt', 'Картинка загружена'); }, 3000) }); }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <img src="https://i.pinimg.com/236x/96/ed/20/96ed206c3206f0cfb9a3abae7660873.jpg" alt="Картинка не загружена">