0

HI, I've got:

<script language="javascript" type="text/javascript">
$(document).ready(function() {
 $("#thumbs a").click( function() {
      var BGswitch = $(this).attr("href");
      $("#target").css("background-image", "url(BGswitch)");
      return false;
      });
});
</script>

And it's not quite working--when I look at the code, the variable itself (BGswitch) is being put in the background-image slot instead of the value of the variable which is supposed to be the href.... Anyone? Some kind of syntax error or something?

THANK YOU!

0

3 Answers 3

1
$("#target").attr("background-image", "url(" + BGswitch + ")");

Check this

Sign up to request clarification or add additional context in comments.

Comments

1

"url(BGswitch)" is literally the string "url(BGswitch)". You need to build the string by concatenation:

"url(" + BGswitch + ")"

Comments

1

Shouldn't it be

$("#target").css("background-image", "url("+BGswitch+")");

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.