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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript and html

Status
Not open for further replies.

ecannizzo

Programmer
Joined
Sep 19, 2000
Messages
213
Location
US
I'm trying to write a hyperlink out in javascript, but I'm just getting the text written out to the screen. If I put a document.write() around it, it does create the link, but it overwrites the whole page. Is there anyway to write out html without overwriting the whole page?

Thanks!
 
you could try giving an div and id and then writing to the innerhtml of the div. via something like this.
Code:
<html>
<script type="text/javascript">
function writelink(){
	document.getElementById('myDiv').innerHTML="<a href='[URL unfurl="true"]www.google.com'>googles</a>";[/URL]
}
</script>
<body>
text
<div id="myDiv"> my div text</div>
</body>
<button onclick="writelink()"> write link to div</button>
</html>
 
This should also work with span tags for inline elements.
 
j4606's is the preferred method (in my opinion), but just to show you how to use the document.write method, here's an example:

Code:
<html>
<head>
  <title>document.write()</title>
</head>
<body>
<h1>The hyperlink below is written with document.write():</h1>
<script type="text/javascript"><!--
document.write("<a href='[URL unfurl="true"]http://www.google.com/'>googles</a>");[/URL]
//--></script>
</body>
</html>



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top