newline character inside title attribute

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

newline character inside title attribute

Post 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">
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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>
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

Post 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
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

Post by newmember »

thanks guys :D
Post Reply