473,385 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Setting a link URL for a div

DB
I'm just getting into DHTML, and there's one thing I'm getting stuck on
in my current project. I'm building a list of destinations to display in
a window. Each one is in its own separate div. But I can't seem to
figure out how to add a link to those div's on the fly in my script. Is
there a way to do that in JavaScript?
Oct 30 '06 #1
2 1337
DB said the following on 10/30/2006 3:23 PM:
I'm just getting into DHTML, and there's one thing I'm getting stuck on
in my current project. I'm building a list of destinations to display in
a window. Each one is in its own separate div. But I can't seem to
figure out how to add a link to those div's on the fly in my script. Is
there a way to do that in JavaScript?
Yes. And how you would do it depends on the HTML you use. Why is each
link in it's own div though? That's overkill if all it is for is to hold
a link.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Oct 30 '06 #2
ASM
DB a écrit :
I'm just getting into DHTML, and there's one thing I'm getting stuck on
in my current project. I'm building a list of destinations to display in
a window. Each one is in its own separate div. But I can't seem to
figure out how to add a link to those div's on the fly in my script. Is
there a way to do that in JavaScript?
function addLink(divId,link) {
// search, get text inside the div of id div
var txt = document.getElementById(divId);
while(txt.nodeType != 3) txt = txt.firstChild;
// new link tag
var L = document.createElement('A');
// new link href
L.href = link;
// insertion text to new link (precedent text catched)
L.innerHTML = txt.nodeValue;
// place of new link in document body
var target = txt.parentNode;
// delete old text
target.innerHTML = ''
// insertion
target.appendChild(L);
}

</script>
<div id="e1"><p>essai 1</p></div>
<div id="e2"><p>essai 2</p></div>
<div id="e3"><p>essai 3</p></div>
<p><a href="#"
onclick="addLink('e2','page2.htm');return false;">
page 2</a></p>

--
ASM
Oct 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Arne | last post by:
During testing <div style="overflow:auto;"> in CSS I noticed the mousewheel would work in Mozilla only after I made a <a href="#">some text</a> link and clicked on that, within the div. It...
0
by: Xiaofeng Zhang | last post by:
when I compile my project setting, there are many LINK errors. But when I compile my project under debug setting, everything is OK. How can I deal with it? The errors is followed. Linking......
2
by: Hasan Ammar | last post by:
Is it possible to set up hotkeys using onkeypress? I know it can be done with the usual alphanumeric keys, but what about function keys? or using ctrl/alt combinations? Does anybody have a...
0
by: Praveen | last post by:
Hello. I am writing some code that accepts a DFS Link and Username and grants that User permissions to the physical directory that the DFS Link corresponds to. I am using the System.Management...
3
by: CSDunn | last post by:
Hello, I currently have an Access 2003 ADP Report/Subreport set up in which I have 12 subreports in a single main report that are located in a group header called 'PermnumHeader' (Permnum would be...
2
by: junlia | last post by:
Hi All, I am working on a project that acts as a bridge. It does some checking with post xml data, and then redirects the request to an appropriate page. However, we find that depends on the...
1
by: bissatch | last post by:
Hi, I am having a problem when setting the padding of <a> tags within a link. A stripped down version of the page can be viewed at: http://www.martynbissett.co.uk/_sfa/index_test.php Its...
2
by: anathema | last post by:
this is not specifically behaviour related, but i thought i would risk asking anyway. i am working on a script that triggers a blind down or blind up effect by clicking on a particular link. it...
4
by: David Veeneman | last post by:
I'm creating a UserControl that uses a LinkLabel. For reasons that I won't bore everyone with, I don't want the LinkLable to show the default hand cursor when the mouse enters the control. Should...
8
by: Jeff | last post by:
ASP.NET 2.0 I'm wondering how to set the color of a visited HyperLinkField (the link text) in a GridView?? Here is the markup of the HyperLinkField I have problems with: <asp:HyperLinkField...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.