JQuery change the value of an <img

后端 未结 5 1648
旧时难觅i
旧时难觅i 2021-02-05 12:28

I need some simple JQuery code so I can change the src value of a specific img.

It\'s currently:


<         


        
5条回答
  •  执笔经年
    2021-02-05 13:23

    Using: $(function(){ ... });

    You can use:

    $('#id').attr('src', 'newImage.jpg');
    

    to change the image source immediately.


    Alternatively, you can use jQuery animations to change an image.

    JS

    $("#id1").fadeOut();
    $("#id2").delay(200).fadeIn();
    

    HTML

    (Don't forget to change the CSS of #id2 and put display: none as initial state).

提交回复
热议问题