Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New line inside javascript

Status
Not open for further replies.

jamiecottonuk

Technical User
Oct 29, 2007
12
GB
Hi All,

I have the following code which runs fine

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Untitled Document</title>
		<script type="text/javascript">
			function changeContent(id,shtml) 
			{
				if (document.getElementById || document.all) 
				{
					var el = document.getElementById? document.getElementById(id): document.all[id];
					if (el && typeof el.innerHTML != "undefined") el.innerHTML = shtml;
				}
			}
			
			function myMessage(message)
			{
				alert(message)
			}
		</script>
	</head>
	<body>
		<div id="sidebar" style="width:300px; border:1px solid black">
			<a href="#" onclick="changeContent('content',' More content <br/><a href=\'#\' onclick=myMessage(\'hello&nbsp;jamie\')>another Link</a>');" /> Click here to change content</a>
	</div>
	<br/>
	<div id="content" style="width:300px; border:1px solid black">
	</div>
</body>
</html>

However I want it so that hello and jamie are displayed on 2 lines so like
Hello
Jamie

I know you have to put &nbsp; to add a space but what do you have to put if you want to add a new line

Cheers
 
[tt] <a href="#" onclick="changeContent('content',' More content <br/><a href=\'#\' onclick=myMessage(\'hello[highlight]\\x0a[/highlight]jamie\')>another Link</a>');" /> Click here to change content</a>[/tt]
 
or..

I use \n for new lines on alerts in Javascript.

Alert("Hello\nJamie");


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top