0

I have this line of code:

var bgposh = "-37";


$(element).find('.toggle_box').css({'-webkit-transition': 'background-position 0.2s linear', 'background-position': '147px "+ bgposh +"px'});

but the background position does not get set. I think it is because there is no space between px and bgposh. How can I add one? I tried + + but that does not seem to work.

Thanks a lot :)

2
  • 1
    You can't mix single quotes with double quotes. Javascript supports both, but if you open a string literal with a single quote, then you also have to close with one. Commented May 29, 2011 at 23:39
  • why did I get a -1? was this not well asked? or am I too stupid to not deserve one? :s Commented May 29, 2011 at 23:54

2 Answers 2

4

Little syntax error i think with your bgposh variable

$(element).find('.toggle_box').css(
   {'-webkit-transition': 'background-position 0.2s linear', 
    'background-position': '147px '+ bgposh +'px'
   });
Sign up to request clarification or add additional context in comments.

3 Comments

thank you sir, this fixes the problem :). I ddidn't know there was a difference between " and ' but thanks for pointing that out :)
There is actually no difference. Your problem was just that you started a string with a single quote and attempted to end it with a double quote for some reason.
oh yeah now that you explained it i feel really stupid :p thanks.
2

No, it is because with this code you have set background-position to 147px "+ bgposh +"px.

You have wrong quotes. The correct version looks like this (notice different quotes):

$(element).find('.toggle_box').css({
    '-webkit-transition': 'background-position 0.2s linear',
    'background-position': '147px ' + bgposh + 'px'
});

3 Comments

let's assume that var bgposh = "-37"
You may assume what you want to, the double-quotes still be wrong there
@SnippetSpace Lets look at the example: jsfiddle.net/NfgPf

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.