Solved

adding a hyperlink or href to a div

Posted on 2010-09-02
4
684 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:
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

726 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