There is a line: var error_text = 'Password does not meet the requirements: \ - at least 8 characters. \ - at least 1 number. \ - at least 1 lowercase character. \ - at least 1 uppercase character'; var error_text = 'Password does not meet the requirements: \ - at least 8 characters. \ - at least 1 number. \ - at least 1 lowercase character. \ - at least 1 uppercase character';

I pass this line to the method that displays an error in front of the input field:

viewError(password_status, password_tooltip, error_text);

In the method I set the text to the block.

How to make a line break? I tried it \n but it does not work.

  • if you want to transfer to html, then use its <br> tag. but in general, and \n should work - lexxl
  • You do not have a line break in error_text, enclose the text in such quotes: `, and in html use the style white-space: pre-wrap; - Vladimir Gamalyan
  • one
    @Tsyklop Well, if you transmit a clean text, then yes. for tags to work, you need to pass html-code, for example the .innerHTML () method. PS In your example, instead of \ n it’s just a slash, did you try to use \ n exactly? - lexxl
  • one
    What kind of block and with what CSS properties? What code do you use to add this text? Give a minimally reproducible example. And then you can guess for a long time on the spiritualist board with your mean data. Just because the elementary code can be dispensed with the given data, the link to jsfiidle and in the above information there are no reasons for the reverse behavior. - Alex Krass
  • one
    And most likely you use somewhere in the depths of the viewError method, which is secret for us, instead of $("#element").html(error_text) method $("#element").text(error_text) , which escapes all your attempts to insert tags . - Alex Krass

1 answer 1

Remove the line breaks in the JS code and use \n :

 var error_text = 'Password does not meet the requirements: \n - at least 8 characters. \n - at least 1 number. \n - at least 1 lowercase character. \n - at least 1 uppercase character'; alert(error_text); 

Or use <br> :

 var error_text = 'Password does not meet the requirements: <br>' + '- at least 8 characters. <br>' + '- at least 1 number. <br>' + '- at least 1 lowercase character. <br>' + '- at least 1 uppercase character'; document.write(error_text); 

  • I inserted the <pre> tag there and made the addition not of text but html and it all worked. Thank. - Tsyklop
  • @Tsyklop, and I deleted my comment, I thought it would not help :) - MasterAlex
  • @Tsyklop glad that your problem is solved. mark the answer accepted, if he helped you, by clicking the check mark to the left of the answer - lexxl