What's The Correct Way To Set Src Attribute In JQuery?

前端 未结 5 746
日久生厌
日久生厌 2020-12-15 16:07

Suppose I have the following HTML:


I would like to switch the src to bar2.jpg

5条回答
  •  悲&欢浪女
    2020-12-15 16:27

    When you do this:

    $("#foo").attr("src", "bar2.jpg");
    

    The previous src is replaced.

    So you don't need:

    $("#foo").removeAttr("src");
    

    You can confirm it out here

提交回复
热议问题