adding a hyperlink or href to a div

Posted on 2010-09-02
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.
Question by:TrialUser
  • 2
LVL 40

Accepted Solution

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



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

LVL 13

Assisted Solution

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");



Author Comment

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");
            // to create a label to the link
            var lb=document.createTextNode("Product 1");

Author Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

863 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

24 Experts available now in Live!

Get 1:1 Help Now