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

Link Disappearing

Status
Not open for further replies.

hiyatran

Technical User
Aug 7, 2010
21
CA
How do I prevent my Link from disappearing??
When I click on the link, "Click Here"

It display, "Look At Me!!" but the link, "Click Here" is GONE
Is there a way to keep my link, "Click Here" from disappearing?
So when I click on the link, "Click Here" the content, "Look At Me!!" should display as well.
thanks


Here are my codes
<html>
<head>

<script type="text/javascript">
function display() {
document.writeln("Look At Me!!");
}
</script>
</head>

<body>
<a href="google.com" onClick="display()">Click Here</a>
</body>

</html>

 
Yes, don't use document.write. Once the page has loaded, document.write overwrites the entire contents of the page thus causing any html, including your link, to disappear.

If you need to modify text in an existing page without overwriting it, use the innerHTML property of any element you have there to output text.

For instance:

Code:
<html>
<head>

<script type="text/javascript"> 
function display() {
   document.[red]getElementById('mytext').innerHTML=[/red]"Look At Me!!";
}
</script>
</head>

<body>
<a href="google.com" onClick="display()">Click Here</a>
[red]<span id="mytext"></span>[/red]
</body>

</html>

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top