By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,773 Members | 1,334 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,773 IT Pros & Developers. It's quick & easy.

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

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

thanks
Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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?

Jul 23 '05 #2

P: n/a
Mel
< a href=xxx>ABCD</a>

ABCD is what i need to change :-)

thanks

"Lee" <RE**************@cox.net> wrote in message
news:d1*********@drn.newsguy.com...
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?

Jul 23 '05 #3

P: n/a
Lee
Mel said:

< a href=xxx>ABCD</a>

ABCD is what i need to change :-)

thanks

"Lee" <RE**************@cox.net> wrote in message
news:d1*********@drn.newsguy.com...
Mel said:
>
>can someone post a simple javascript to change the text of the <href> forme >?


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

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

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

Jul 23 '05 #4

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

ABCD is what i need to change :-)

thanks

"Lee" <RE**************@cox.net> wrote in message
news:d1*********@drn.newsguy.com...
Mel said:

can someone post a simple javascript to change the text of the <href> for

[...]

<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>

--
Rob
Jul 23 '05 #5

P: n/a
Mel wrote:
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>

Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.