I’m targetting the image in the following HTML
<h1 class="logo-site-name">
<span id="logo">
<a href="http://some.link">
<img src="http://www.other.com/some.gif">
</a>
</span>
</h1>
And I’m attempting to replace the image with the following code, but it isn’t working. Am I selecting & modifying correctly?
$('#logo').children('img').attr('src', 'http://www.domain.com/image.gif');
Your
imgelement isn’t a child oflogo, it is a descendant.You could do
The
firstis optional, but if you only have one I like to restrict.