2

This is my code:

$(document).ready(function(){ var $question_mark = "?"; var $question = "They look " . concat($question_mark) . concat(" the plaining the wall ") . concat($question_mark) . concat(" the girls"); $('.scrolling_quiz').text($question); }); 

this code shows a string like: They look ? the planing the wall ? the girls

now i want to add background:blue just to the "?". not to the full sentence. Can you please send me an idea or solution to this?

2
  • You can wrap the ? by span and add color to span. Commented May 8, 2016 at 17:19
  • Use the deprecated font tag which is otherwise universally supported and used widely by all sorts of html generators and RTEs: var $question_mark = "<font color=blue>?</font>"; Commented May 8, 2016 at 17:38

1 Answer 1

1

To expand on Mehdi's idea, you might have something like:

var $question_mark = "<span class='blue'>?</span>"; var $question = "They look " + $question_mark + " the plaining the wall " + $question_mark + " the girls"; 

And then your css will look like:

.blue { background: blue; } 

If you meant that you want everything between the ?'s to be blue, you could do this:

var $question_mark = "?"; var $question = "They look <span class='blue'>" + $question_mark + " the plaining the wall " + $question_mark + "</span> the girls"; 

EDIT

I have created a jsfiddle and fixed the issue.

https://jsfiddle.net/uc42z0LL/6/

I suspect you weren't including the jquery dependency.

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

2 Comments

can you please check my link and tell why it's not working? I followed your system: jsfiddle.net/fLvo8hgc
@shaylakarzon I changed $('.scrolling_quiz').text($question); to $('.scrolling_quiz').html($question);. This way, the text you want to show is treated as HTML instead of plaintext. jsfiddle.net/fLvo8hgc/1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.