newline - Javascript set title with new lines - Stack Overflow

admin2025-04-26  1

None of these makes the title appear with a new line.

ele.title = 'abc 
 ABC';
ele.setAttribute('title', 'abc 
 ABC');

If i load the page with that element having the same title, then it would be with a new line. I've even tried with different new line markings.

None of these makes the title appear with a new line.

ele.title = 'abc 
 ABC';
ele.setAttribute('title', 'abc 
 ABC');

If i load the page with that element having the same title, then it would be with a new line. I've even tried with different new line markings.

Share Improve this question asked Jan 6, 2017 at 19:04 KruppKrupp 3731 gold badge6 silver badges18 bronze badges 6
  • 1 Maybe try: \n . Although the title element probably won't allow any linebreaks. – zer00ne Commented Jan 6, 2017 at 19:07
  • It's cazy! if i set it through the console - it works. But what i do is to get the text from PHP and then set it as a title. There - nothing works – Krupp Commented Jan 6, 2017 at 19:08
  • Look at the generated source (right click -> view page source). It's possible that PHP escapes the ampersand or does something else to the text. – JJJ Commented Jan 6, 2017 at 19:09
  • Nope. It's through AJAX, and the text received is not escaped - just as it is supposed to be – Krupp Commented Jan 6, 2017 at 19:12
  • 1 Why do you want a newline in the title? Most window systems won't display window titles with multiple lines. – Barmar Commented Jan 6, 2017 at 19:48
 |  Show 1 more ment

1 Answer 1

Reset to default 7

This works for me

ele.title =  'abc' + "\u000d" + 'ABC';  

This is the Unicode escape sequence for the carriage return (CR). I am not sure why HTML entity names or numbers do not work in the title, but the Unicode escape sequence is what works.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745603530a309447.html

最新回复(0)