469,292 Members | 1,335 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,292 developers. It's quick & easy.

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

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

thanks
Jul 23 '05 #1
5 25777
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
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
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
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
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.

Similar topics

9 posts views Thread by Peter | last post: by
17 posts views Thread by Christopher Nelson | last post: by
3 posts views Thread by Charlie Dison | last post: by
2 posts views Thread by Rinaldo | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.