Reputation: 25
<div class="branding">
<h1 class="logo">
<a href="http://www.whatever.com/" class="logo">
<img src="http://www.whatever.com/test.png"></a>
</h1>
</div>
I am trying to access the image src with the following to no avail:
$("a.logo img").html("<img src='http://www.whatever.com/newimage.png'>");
The reason I am doing this is because the image is on a third party that I can't access the codebase to make the change so I am trying to rip out their with my code.
Upvotes: 0
Views: 97
Reputation: 25
I figured out the answer:
$('a.logo img').attr("src", "http://www.whatever.com/newimage.png" );
Thanks!
Upvotes: -2
Reputation: 360812
.html() changes the html CONTENT of a node, e.g.
orig: <p>foo</p>
$('p').html('bar');
neW: <p>bar</p>
An <img>
has NO content. Try
$('p.logo img').attr('src', 'new url here');
Upvotes: 1
Reputation: 82251
src is attribute. You should use .attr()
to get/set attribute values using jquery:
$("a.logo img").attr("src","http://www.whatever.com/newimage.png");
Upvotes: 3