...

View Full Version : Make <div> to <a href="">



Jesper Møller
06-24-2006, 03:08 PM
How do i make this <div id="her"> URL</div>

to a link like this <a href="http://thesite/thefolder/thedocument.html?detect=false">Link</a>


So far i have this

function writeLink() {
var locationElement = document.getElementById("her");
var linkText = "Link";
var urlNode = document.createTextNode("<a href=\""+window.location.href + "?detect=false\">"+linkText+"<\/a>");
locationElement.appendChild(urlNode);
}

but that dosnt make it a link :confused:

vwphillips
06-24-2006, 03:52 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
</head>

<body>
How do i make this

<div id="her"> URL</div>


<input type="button" name="" value="DoIt" onclick="writeLink();"/>
to a link like this <a href="http://thesite/thefolder/thedocument.html?detect=false">Link</a>


So far i have this
<script language="JavaScript" type="text/javascript">


function writeLink() {
var locationElement = document.getElementById("her");
var lnk=document.createElement('A');
lnk.href=window.location.href + '?detect=false\ ';
lnk.appendChild(document.createTextNode('Link'));
locationElement.parentNode.replaceChild(lnk,locationElement);
}



</script>

</body>

</html>

Jesper Møller
06-24-2006, 03:55 PM
Thanks :thumbsup:

coothead
06-24-2006, 04:27 PM
Hi there Jesper Møller,

as I have just finished this example, I may as well post it - even though it's a little bit late. ;)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">
<!--
window.onload=function() {
obj=document.getElementById('her');
obj.onclick=function() {
obj.firstChild.data='';
link=document.createElement('a');
link.setAttribute('href','http://thesite/thefolder/thedocument.html?detect=false');
linkText=document.createTextNode('Link');
link.appendChild(linkText);
obj.appendChild(link);
}
}
//-->
</script>

</head>
<body>

<div id="her">URL - click for link</div>

</body>
</html>




coothead

Jesper Møller
06-24-2006, 04:32 PM
Thank you coothead :-)

I think i understand you version a little better ;-)

coothead
06-24-2006, 04:43 PM
Hi there Jesper Møller

I think I understand your version a little better
It was a good job that I posted it then. :)
When I saw that Vic had posted a solution, I nearly popped my little effort into the Recycle Bin. :D

coothead

Jesper Møller
06-24-2006, 04:46 PM
:) Glad you dint ... a newbee like me like it when it makes sens .. not youst works :rolleyes:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum