ewein
ewein

Reputation: 2735

Changing HTML image source

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

Answers (8)

Yaron
Yaron

Reputation: 1620

Instead of ".css('src', "foo.png");"

use ".attr('src', "foo.png");"

Upvotes: 0

VisioN
VisioN

Reputation: 145428

newEntryRow.find("img").attr('src', "foo.png");

Upvotes: 0

ShankarSangoli
ShankarSangoli

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

Diodeus - James MacFarlane
Diodeus - James MacFarlane

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

Icarus
Icarus

Reputation: 63964

Try:

 newEntryRow.find("img").attr("src","foo.png");

Upvotes: 0

Brad
Brad

Reputation: 163448

newEntryRow.find('img').attr('src', 'foo.png');

http://api.jquery.com/attr/

Upvotes: 0

chepe263
chepe263

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

Selvakumar Arumugam
Selvakumar Arumugam

Reputation: 79830

Use .attr to change the attribute of an element,

newEntryRow.find("img").attr('src', "foo.png")

Upvotes: 4

Related Questions