example on how to change href's text needed....

L

Lee

Mel said:
can someone post a simple javascript to change the text of the <href> for me
?

What is "the text of the <href>" ?
The visible text of the link, or the href attribute value?
 
L

Lee

Mel said:
< a href=xxx>ABCD</a>

ABCD is what i need to change :)

thanks


<a id="Link1" href="xxx">ABCD</a>

<script type="text/javascript">
document.getElementById("Link1").innerHTML="WXYZ";
</script>
 
R

RobG

Lee said:
Mel said:
< a href=xxx>ABCD</a>

ABCD is what i need to change :)

thanks
[...]


<a id="Link1" href="xxx">ABCD</a>

<script type="text/javascript">
document.getElementById("Link1").innerHTML="WXYZ";
</script>

A couple of other alternatives:

Really simple:

<a id="Link1" href="#" onclick="
this.innerHTML = 'WXYZ';">ABCD</a>

With a function, passing a reference:

<a id="Link1" href="#" onclick="modText(this);">ABCD</a>

<script type="text/javascript">
function modText(ele){
ele.innerHTML="WXYZ";
}
</script>

As above, but using DOM rather than the non-standard innerHTML:

<a id="Link1" href="#" onclick="modText(this);">ABCD</a>

<script type="text/javascript">
function modText(ele){
ele.childNodes[0].nodeValue = "WXYZ";
}
</script>
 
R

RobB

Mel said:
can someone post a simple javascript to change the text of the <href> for me
?

thanks

<html>
<head>
<style type="text/css">

a {display: block; font: 500% tahoma; color: crimson;}

</style>
<script type="text/javascript">

function setLinkText(sLink_id, sText)
{
var el;
if (document.getElementById
&& (el = document.getElementById(sLink_id))
|| document.all
&& (el = document.all[sLink_id]))
{
while (el.hasChildNodes())
el.removeChild(el.lastChild);
el.appendChild(document.createTextNode(sText));
}
}

onload = function()
{
setTimeout("setLinkText('foo1', 'zippity');", 2000);
setTimeout("setLinkText('foo2', 'doo');", 3000);
setTimeout("setLinkText('foo3', 'dah !');", 3500);
}

</script>
</head>
<body>
<a id="foo1" href="#">z</a>
<a id="foo2" href="#">d</a>
<a id="foo3" href="#">d</a>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top