0

I want to have the following text with break lines in my .js file:

button = 0;

var cardTextDefault = function(textInProzent){
    $("#button").text('text part I.\n is:'+percent+'%\n\n text part two');
} 

This var is afterwards called when clicking the button:

cardTextDefault(button.value);

Do you have any clue why \n is not breaking my line?

jotNewie
  • 416
  • 4
  • 15

1 Answers1

3

That's not how line breaks work in HTML (/jQuery)

Use this instead:

button = 0;

var cardTextDefault = function(textInProzent){
    $("#button").html('text part I.<br /> is:'+percent+'%<br /><br /> text part two');
} 

Note that I replaced .text with .html. .text would've escaped the HTML in there.

Cerbrus
  • 65,559
  • 18
  • 128
  • 140