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
  • 426
  • 4
  • 17

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
  • 70,800
  • 18
  • 132
  • 147