Page 1 of 1

newline character inside title attribute

Posted: Sun Dec 18, 2005 2:33 pm
by newmember
hi

why '\n' character doesn't create line breaks when used inside title attribute?

something like this: <input title="line 1\nline 2\nline 3" type="radio">

Posted: Sun Dec 18, 2005 2:59 pm
by Chris Corbyn
You might need \r\n if you're on windows. You need to have a look at your source code to see what's appearing.

Real line breaks work though.

Code: Select all

<div title="line1
line2
line3
line4">Text here</div>

Posted: Sun Dec 18, 2005 3:28 pm
by newmember
firefox also doesn't display newlines.in both browsers is '\n' as is.
You need to have a look at your source code to see what's appearing.
the code is simply bunch of radio inputs having same name like these
<input title="line 1\nline 2\nline 3" type="radio" name="date">

anyway i use ',' instead of '\n'. it is not that critical :D

Posted: Sun Dec 18, 2005 9:47 pm
by redmonkey
You need to use the HTML entitie in order to define new lines within the title attribute i.e.

Code: Select all

title="Some line

A new line"
(used PHP tags as the 'code' tags were stripping the entities)

However, while this works for most browsers, it does not render correctly in any Gecko based browser (i.e. Firefox or Mozilla). Personally I think that's down to Mozilla's misinterpretation of the spec but that's an entirely different debate/subject.

Posted: Mon Dec 19, 2005 9:44 am
by Chris Corbyn
Yeah sorry I didn't realise you were referring to using \n directly as the output, I thought this was somewhere in the PHP code. SGML parsers won't parse escape sequences like such and they'll just parse them as plain text, in the same way as if you opened notepad in windows and typed the following then saved it.

Code: Select all

This is line one\nThis is line two
Ascii entity codes are what SGML parsers use for this like ~redmonkey says.

Posted: Tue Dec 20, 2005 2:13 pm
by newmember
thanks guys :D