0

I want to include a single line break in a jquery variable but I am getting a syntax error with my operator:

var $answer = $("\n" + "<table class='answer'><tbody><tr><td>3. Answer:</td></tr></tbody></table>" + "\n"); 

What is the correct way for me to be able to include a single line break before and after this table?

3
  • Maybe I'm not looking at this right, but can't you just add a <br /> before and after the <table>? Alternatively, I personally would use css for spacing. Commented Dec 27, 2012 at 18:05
  • 2
    use <br> instead of \n. Commented Dec 27, 2012 at 18:05
  • 1
    I don't get a syntax error with your code Commented Dec 27, 2012 at 18:07

2 Answers 2

4

I'd recommend using css for your styling, however this should be the answer you're looking for:

var $answer = $("<br /><table class='answer'><tbody><tr><td>3. Answer:</td></tr></tbody></table><br />"); 
Sign up to request clarification or add additional context in comments.

Comments

-1

try:

var $answer = "<br/><table class='answer'><tbody><tr><td>3. Answer:</td></tr></tbody</table><br />"; 

2 Comments

And why it this different than the other answer ?
-1: Depends on what you're doing. You can't chain jQuery methods off a string as in your example. Ultimately if you plan to do anything like .find(), .appendTo(), etc - then you'll have to wrap it in $().

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.