1

I'm trying to do something like this:

$('#player-container').html('<div id="film-player" class="flowplayer play-button is-splash"  style="background:#777 url(myVariable) no-repeat;">');

The html isn't showing up because it doesn't in code blocks here. Basically I'm trying to nest a variable like this: style equals background url(myVariable) in the html I'm assigning to the element dynamically.

0

1 Answer 1

5

Since you started the string with single quotes you use ' again and + to concatenate like this:
url(' + myVariable + ').

So your code should be:

$('#player-container').html('<div id="film-player" class="flowplayer play-button is-splash"   style="background:#777 url('+myVariable+') no-repeat;">');

More info about concatenation operator (in javascript) at MDN

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

3 Comments

Thanks, I was just doing that on my own while you answered, works great!
@Wendy, great! Maybe you can click to accept the answer anyway ;)
Oops, I thought I did! Voted it up instead, that's what happens when you're clicking too fast...

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.