Solved

adding a hyperlink or href to a div

Posted on 2010-09-02
4
672 Views
Last Modified: 2013-11-19
I have a div with list of shopping cart items. When users click on "add to cart" button, i would like to add a hyperlink to href to the div.
The div itself shows on mouseover a shopping cart image that I show/hide using javascript.

Now, How can I 1) dynamically add the links to the div.
2) should the links be href or asp:hyperlink.

Please help. any suggetsion would be great. thanks a ton.
0
Comment
Question by:TrialUser
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 250 total points
ID: 33586571
you can do
var link = document.createElement("a");
link.setAttribute("href","");

document.getElementById("divId").appendChild(link);

or

document.getElementById("divId").innerHTML = document.getElementById("divId").innerHTML  + "<a href=''>";

0
 
LVL 13

Assisted Solution

by:ansudhindra
ansudhindra earned 250 total points
ID: 33586771
var link = document.createElement("a");
link.setAttribute("href","your url");

if link.setAttribute doesnot work then you can do
link.href="your url";

// to create a label to the link
var lb=document.createTextNode("Link Title");
link.appendChild(lb);

document.getElementById("divId").appendChild(link);

0
 

Author Comment

by:TrialUser
ID: 33587608
Ok , the above suggestion works great.  the code i used is as follows. only other thing is , I need like a <br /> after every link. how can i make sure the link is added in a newline each time. please help thanks

 function AddLink()
        {
            var link = document.createElement("a");
            link.setAttribute("href","Product.aspx");
            // to create a label to the link
            var lb=document.createTextNode("Product 1");
            link.appendChild(lb);
            document.getElementById("divCart").appendChild(link);
           
        }        
0
 

Author Comment

by:TrialUser
ID: 33587709
oh, i got it added a br. thanks a ton for your quick response.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to add loader animation to a page ? 2 22
Accessing data in JSON response.d 4 29
onOpen 14 39
Cordova Camera plugin fails 2 19
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now