How can I select an image inside of a div to change its source?

前端 未结 2 1720
再見小時候
再見小時候 2021-02-07 04:38

I have the following div and I know the selector Id of the DIV.

 
2条回答
  •  忘了有多久
    2021-02-07 05:07

    $('.event').children('img').attr('src', '');
    

    This selects all the elements with the event class and then finds their children img elements. If you have multiple matches and want to change their sources differently then you can use $.each() to iterate through them.

    • .children(): http://api.jquery.com/children
    • .attr() : http://api.jquery.com/attr

    A demo: http://jsfiddle.net/aPzgR/

提交回复
热议问题