1

The application is working on dreamweaver but when I try it on Chrome or IE it dones't work. I know where the issue is but I don't now how to fix it. It has something to do with applying variable as an img src. The code is setup at http://jsfiddle.net/v9rxH/

the issue is in the line

 $(".topImage").attr("src", "'" + obj[randomNumA].urlTop + "'");
 $(".middleImage").attr("src", "'" + obj[randomNumB].urlMiddle + "'");
 $(".bottomImage").attr("src", "'" + obj[randomNumC].urlBottom + "'");

when the browser renders it is show

 <img src="'http://placehold.it/300x100&text=SecondBottom'" class="bottomImage">

it's adding additional single quotes(' ') in src. Based on that, I removed the single quotes and it shows the variable as text instead of it's value. What am I missing? Thanks in advance. Rex

4 Answers 4

6

You're putting the single quotes around it with "'" - you don't need to, using .attr() handles that for you:

$(".topImage").attr("src", obj[randomNumA].urlTop);
$(".middleImage").attr("src", obj[randomNumB].urlMiddle);
$(".bottomImage").attr("src", obj[randomNumC].urlBottom);
Sign up to request clarification or add additional context in comments.

Comments

2

Remove single quotes from obj[randomNumN].urlTop.

Comments

1

Try,

 $(".topImage").attr("src", obj[randomNumA].urlTop);
 $(".middleImage").attr("src", obj[randomNumB].urlMiddle);
 $(".bottomImage").attr("src", obj[randomNumC].urlBottom);

Comments

1

Use this instead:

$(".topImage").attr("src", obj[randomNumA].urlTop);
$(".middleImage").attr("src", obj[randomNumB].urlMiddle);
$(".bottomImage").attr("src", obj[randomNumC].urlBottom);

jsFiddle example.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.