Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Mel
Guest
 
Posts: n/a
#1: Jul 23 '05
can someone post a simple javascript to change the text of the <href> for me
?

thanks



Lee
Guest
 
Posts: n/a
#2: Jul 23 '05

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


Mel said:[color=blue]
>
>can someone post a simple javascript to change the text of the <href> for me
>?[/color]

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

Mel
Guest
 
Posts: n/a
#3: Jul 23 '05

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


< a href=xxx>ABCD</a>

ABCD is what i need to change :-)

thanks

"Lee" <REM0VElbspamtrap@cox.net> wrote in message
news:d1n7r602kjc@drn.newsguy.com...[color=blue]
> Mel said:[color=green]
> >
> >can someone post a simple javascript to change the text of the <href> for[/color][/color]
me[color=blue][color=green]
> >?[/color]
>
> What is "the text of the <href>" ?
> The visible text of the link, or the href attribute value?
>[/color]


Lee
Guest
 
Posts: n/a
#4: Jul 23 '05

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


Mel said:[color=blue]
>
>< a href=xxx>ABCD</a>
>
>ABCD is what i need to change :-)
>
>thanks
>
>"Lee" <REM0VElbspamtrap@cox.net> wrote in message
>news:d1n7r602kjc@drn.newsguy.com...[color=green]
>> Mel said:[color=darkred]
>> >
>> >can someone post a simple javascript to change the text of the <href> for[/color][/color]
>me[color=green][color=darkred]
>> >?[/color]
>>
>> What is "the text of the <href>" ?
>> The visible text of the link, or the href attribute value?[/color][/color]


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

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

RobG
Guest
 
Posts: n/a
#5: Jul 23 '05

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


Lee wrote:[color=blue]
> Mel said:
>[color=green]
>>< a href=xxx>ABCD</a>
>>
>>ABCD is what i need to change :-)
>>
>>thanks
>>
>>"Lee" <REM0VElbspamtrap@cox.net> wrote in message
>>news:d1n7r602kjc@drn.newsguy.com...
>>[color=darkred]
>>>Mel said:
>>>
>>>>can someone post a simple javascript to change the text of the <href> for[/color]
>>[/color][/color]
[...][color=blue]
>
>
> <a id="Link1" href="xxx">ABCD</a>
>
> <script type="text/javascript">
> document.getElementById("Link1").innerHTML="WXYZ";
> </script>
>[/color]

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
RobB
Guest
 
Posts: n/a
#6: Jul 23 '05

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


Mel wrote:[color=blue]
> can someone post a simple javascript to change the text of the <href>[/color]
for me[color=blue]
> ?
>
> thanks[/color]

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

Closed Thread