Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use a multiline value for an HTML tag attribute? (i.e. how do I escape newline?)

Tags:

How do I include a newline in an HTML tag attribute?

For example:

<a href="somepage.html" onclick="javascript: foo('This is a multiline string. This is the part after the newline.')">some link</a> 

Edit: Sorry, bad example, what if the tag happened to not be in javascript, say:

<sometag someattr="This is a multiline string. This is the part after the newline." /> 

Edit 2: Turns out the newline in the string wasn't my problem, it was the javascript function I was calling. FWIW, "&#10;" can be used for newline in an HTML attribute.

like image 924
Kip Avatar asked Jun 11 '09 21:06

Kip


2 Answers

From what I remember about the HTML standard, character entities work in attributes, so this might work:

<sometag someattr="This is a multiline string.&#10;This is the part after the newline." /> 

I'm not sure if the "newline" you want ought to be &#10; (\n) or &#13;&#10; (\r\n), and I'm not sure if browsers will interpret it the way you want.

Why do you need it? What specific problem are you trying to solve by adding a newline in an HTML tag attribute?

like image 160
Marius Gedminas Avatar answered Sep 19 '22 08:09

Marius Gedminas


To include a multiline value, just continue the text of the html attribute on the next line in your editor e.g.

<input type="submit" value="hallo hallo">  

will put the second hallo under the first

like image 24
edelwater Avatar answered Sep 18 '22 08:09

edelwater