Reputation: 2735
I have some code like below which changes the font of text under a certain condition. newEntryRow.find("p").find("span").css('color','red');
Now I am trying to do the same thing but change the source of an image. I tried something like
newEntryRow.find("img").css('src', "foo.png"
);`
How can I do this?
Upvotes: 1
Views: 215
Reputation: 69915
Use jQuery attr()
method to set any attribute on a dom element.
newEntryRow.find('img').attr('src', 'foo.png');
Reference: http://api.jquery.com/attr/
Upvotes: 0
Reputation: 114417
It's not a CSS property, it's an attribute on the tag itself:
newEntryRow.find("img").attr('src', "foo.png");
Upvotes: 0
Reputation: 2812
use
newEntryRow.find("img").attr('src', "foo.png");
You can also use css to set the image but as a background
newEntryRow.find("img").css('background-image', "url('path/to/pic')")
Don't forget to set width, height and no-repeat of the element.
Upvotes: 1
Reputation: 79830
Use .attr
to change the attribute of an element,
newEntryRow.find("img").attr('src', "foo.png")
Upvotes: 4