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

$('.event').children('img').attr('src', '<source here>');

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/


$('div.event img').attr('src', '/anything');

If you have several divs with event as the class you're better off selecting the div by id if you don't want to change the source of all the images