Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

adding a hyperlink or href to a div

Posted on 2010-09-02
4
Medium Priority
?
704 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 1000 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

610 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