1

I know there are other questions on this site, but I can't get their suggestions to work for me.

I have some JavaScript:

displayString = 'Text to go on line 1'+'<br/>'+'Text to go on line 2'; 

This appears on my webpage as it should, except there is no line break, and it just appears as:

"Text to go on line 1<br/>Text to go on line 2" 

I have tried '/n' too, but that seems to just be omitted.


Actual JavaScript:

$(document).ready(function(){ $('#selectDirect').change(function(){ if ($(this).val() === "450 Litre"){ displayString = '450 Litre Vessel'+'<br/>'+'Combination Valve'; } else if ($(this).val() === "550 Litre"){ displayString = '550 Litre Vessel'+'<br/>'+'Combination Valve'; } $("#choiceDisplay").text(displayString); }); 

2 Answers 2

6

Since you want HTML tags to be processed, you have to use .html(), not .text().

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

Comments

1

Try with .html() instead:

$("#choiceDisplay").html(displayString); 

This will not escape html tags and in this case the <br/> tag.

2 Comments

innerHTML is a DOM attribute, not a jQuery method.
My bad. Use html instead.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.