What is the function to add a link to a graphic in javascript under document.createElement?What is the most efficient way to deep clone an object in JavaScript?Which “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?What is the preferred syntax for defining enums in JavaScript?What is the scope of variables in JavaScript?What is the !! (not not) operator in JavaScript?Set a default parameter value for a JavaScript functionWhat is the JavaScript version of sleep()?What does “use strict” do in JavaScript, and what is the reasoning behind it?What is the 'new' keyword in JavaScript?Is there a standard function to check for null, undefined, or blank variables in JavaScript?
Why did MS-DOS applications built using Turbo Pascal fail to start with a division by zero error on faster systems?
How to stop this icon from appearing on the taskbar?
Are there any music source codes for sound chips?
What is the history of the university asylum law?
What professions would a medieval village with a population of 100 need?
How would one country purchase another?
Can realistic planetary invasion have any meaningful strategy?
How can I watch the 17th (or last, if less) line in files of a folder?
Are there account age or level requirements for obtaining special research?
What is this symbol: semicircles facing eachother
Do AT motherboards (286, 386, 486) really need -5V (besides redirecting it to ISA connectors)?
The remote server returned an error: (401) Unauthorized: While uploading file in document library using App Based Token Authentication
Why is my Earth simulation slower than the reality?
Fancy String Replace
When did G-d say to Yaakov that he will have 12 sons?
Church Booleans
How much code would a codegolf golf if a codegolf could golf code?
Can you feel passing through the sound barrier in an F-16?
Are illustrations in novels frowned upon?
What to say to a student who has failed?
How do I request a longer than normal leave of absence period for my wedding?
Why is less being run unnecessarily by git?
Why did this happen to Thanos's ships at the end of "Avengers: Endgame"?
LeetCode: Pascal's Triangle C#
What is the function to add a link to a graphic in javascript under document.createElement?
What is the most efficient way to deep clone an object in JavaScript?Which “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?What is the preferred syntax for defining enums in JavaScript?What is the scope of variables in JavaScript?What is the !! (not not) operator in JavaScript?Set a default parameter value for a JavaScript functionWhat is the JavaScript version of sleep()?What does “use strict” do in JavaScript, and what is the reasoning behind it?What is the 'new' keyword in JavaScript?Is there a standard function to check for null, undefined, or blank variables in JavaScript?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am setting up a timeline using examples from http://visjs.org/docs/timeline/#Example. Can someone tell me what I need to add a local link to the graphic I have?
I have tried a.href, but maybe I am doing something wrong. Here is a snippet with my code commented out:
var item5 = document.createElement('div');
item5.appendChild(document.createTextNode('item 5'));
item5.appendChild(document.createElement('br'));
var img5 = document.createElement('img');
// img5.a.href = 'attachments/AddDuties.pdf';
img5.src = 'icons/pdf1.png';
img5.style.width = '48px';
img5.style.height = '48px';
item5.appendChild(img5);
Here is the some more code (I cut parts out to reduce size, it works before I add my own code below on image 5:). Image 5 is the one I want link the graphic to a file.
<title>Timeline | Basic demo</title>
<script src="vis-4.21.0/dist/vis.js"></script>
<link href="vis-4.21.0/dist/vis.css" rel="stylesheet" type="text/css" />
</head>
<body>'
<script>
// create a couple of HTML items in various ways
var item1 = document.createElement('div');
item1.appendChild(document.createTextNode('item 1'));
var item4 = 'item <span class="large">4</span>';
**var item5 = document.createElement('div');
item5.appendChild(document.createTextNode('item 5'));
item5.appendChild(document.createElement('br'));
var img5 = document.createElement('img');
// img5.a.href = 'attachments/AddDuties.pdf';
img5.src = 'icons/pdf1.png';
img5.style.width = '48px';
img5.style.height = '48px';
item5.appendChild(img5);**
</body>
I expect to be able to click the graphic and follow the assigned link. I know how to use href in HTML, I just dont know what code needs to tell javascript how to link the graphic in image 5.
javascript graphics href
add a comment |
I am setting up a timeline using examples from http://visjs.org/docs/timeline/#Example. Can someone tell me what I need to add a local link to the graphic I have?
I have tried a.href, but maybe I am doing something wrong. Here is a snippet with my code commented out:
var item5 = document.createElement('div');
item5.appendChild(document.createTextNode('item 5'));
item5.appendChild(document.createElement('br'));
var img5 = document.createElement('img');
// img5.a.href = 'attachments/AddDuties.pdf';
img5.src = 'icons/pdf1.png';
img5.style.width = '48px';
img5.style.height = '48px';
item5.appendChild(img5);
Here is the some more code (I cut parts out to reduce size, it works before I add my own code below on image 5:). Image 5 is the one I want link the graphic to a file.
<title>Timeline | Basic demo</title>
<script src="vis-4.21.0/dist/vis.js"></script>
<link href="vis-4.21.0/dist/vis.css" rel="stylesheet" type="text/css" />
</head>
<body>'
<script>
// create a couple of HTML items in various ways
var item1 = document.createElement('div');
item1.appendChild(document.createTextNode('item 1'));
var item4 = 'item <span class="large">4</span>';
**var item5 = document.createElement('div');
item5.appendChild(document.createTextNode('item 5'));
item5.appendChild(document.createElement('br'));
var img5 = document.createElement('img');
// img5.a.href = 'attachments/AddDuties.pdf';
img5.src = 'icons/pdf1.png';
img5.style.width = '48px';
img5.style.height = '48px';
item5.appendChild(img5);**
</body>
I expect to be able to click the graphic and follow the assigned link. I know how to use href in HTML, I just dont know what code needs to tell javascript how to link the graphic in image 5.
javascript graphics href
What happened when you tried a href?
– Robert Columbia
Mar 27 at 16:41
add a comment |
I am setting up a timeline using examples from http://visjs.org/docs/timeline/#Example. Can someone tell me what I need to add a local link to the graphic I have?
I have tried a.href, but maybe I am doing something wrong. Here is a snippet with my code commented out:
var item5 = document.createElement('div');
item5.appendChild(document.createTextNode('item 5'));
item5.appendChild(document.createElement('br'));
var img5 = document.createElement('img');
// img5.a.href = 'attachments/AddDuties.pdf';
img5.src = 'icons/pdf1.png';
img5.style.width = '48px';
img5.style.height = '48px';
item5.appendChild(img5);
Here is the some more code (I cut parts out to reduce size, it works before I add my own code below on image 5:). Image 5 is the one I want link the graphic to a file.
<title>Timeline | Basic demo</title>
<script src="vis-4.21.0/dist/vis.js"></script>
<link href="vis-4.21.0/dist/vis.css" rel="stylesheet" type="text/css" />
</head>
<body>'
<script>
// create a couple of HTML items in various ways
var item1 = document.createElement('div');
item1.appendChild(document.createTextNode('item 1'));
var item4 = 'item <span class="large">4</span>';
**var item5 = document.createElement('div');
item5.appendChild(document.createTextNode('item 5'));
item5.appendChild(document.createElement('br'));
var img5 = document.createElement('img');
// img5.a.href = 'attachments/AddDuties.pdf';
img5.src = 'icons/pdf1.png';
img5.style.width = '48px';
img5.style.height = '48px';
item5.appendChild(img5);**
</body>
I expect to be able to click the graphic and follow the assigned link. I know how to use href in HTML, I just dont know what code needs to tell javascript how to link the graphic in image 5.
javascript graphics href
I am setting up a timeline using examples from http://visjs.org/docs/timeline/#Example. Can someone tell me what I need to add a local link to the graphic I have?
I have tried a.href, but maybe I am doing something wrong. Here is a snippet with my code commented out:
var item5 = document.createElement('div');
item5.appendChild(document.createTextNode('item 5'));
item5.appendChild(document.createElement('br'));
var img5 = document.createElement('img');
// img5.a.href = 'attachments/AddDuties.pdf';
img5.src = 'icons/pdf1.png';
img5.style.width = '48px';
img5.style.height = '48px';
item5.appendChild(img5);
Here is the some more code (I cut parts out to reduce size, it works before I add my own code below on image 5:). Image 5 is the one I want link the graphic to a file.
<title>Timeline | Basic demo</title>
<script src="vis-4.21.0/dist/vis.js"></script>
<link href="vis-4.21.0/dist/vis.css" rel="stylesheet" type="text/css" />
</head>
<body>'
<script>
// create a couple of HTML items in various ways
var item1 = document.createElement('div');
item1.appendChild(document.createTextNode('item 1'));
var item4 = 'item <span class="large">4</span>';
**var item5 = document.createElement('div');
item5.appendChild(document.createTextNode('item 5'));
item5.appendChild(document.createElement('br'));
var img5 = document.createElement('img');
// img5.a.href = 'attachments/AddDuties.pdf';
img5.src = 'icons/pdf1.png';
img5.style.width = '48px';
img5.style.height = '48px';
item5.appendChild(img5);**
</body>
I expect to be able to click the graphic and follow the assigned link. I know how to use href in HTML, I just dont know what code needs to tell javascript how to link the graphic in image 5.
javascript graphics href
javascript graphics href
asked Mar 27 at 16:39
K-RodK-Rod
1
1
What happened when you tried a href?
– Robert Columbia
Mar 27 at 16:41
add a comment |
What happened when you tried a href?
– Robert Columbia
Mar 27 at 16:41
What happened when you tried a href?
– Robert Columbia
Mar 27 at 16:41
What happened when you tried a href?
– Robert Columbia
Mar 27 at 16:41
add a comment |
1 Answer
1
active
oldest
votes
href is an attribute for the <a> tag. you can't add href to an image.
What you should do is create an <a> element assign the href you want to it and
append the img as a child of that <a> element.
<a href="whatever you want">
<img src=....>
</a>
edit:
if for some reason you can't wrap the image with an <a> you could assign and id to the image and then add an event listener for a click that will redirect you.
Thanks. I do understand how to use the href tag, but in the code above is seems like it should have a line by itself such as `` img5.a.href = 'attachments/DallasAddDuties.pdf'; but this didnt work. If I can use code like you have, where does it go in my code?
– K-Rod
Mar 27 at 19:04
beforeitem5.appendChild(img5);**you could try creating anaelement, saya5assigning anhrefto it. appendingimg5to that newa5element and appendinga5toitem5.
– Max
Mar 27 at 20:34
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55382370%2fwhat-is-the-function-to-add-a-link-to-a-graphic-in-javascript-under-document-cre%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
href is an attribute for the <a> tag. you can't add href to an image.
What you should do is create an <a> element assign the href you want to it and
append the img as a child of that <a> element.
<a href="whatever you want">
<img src=....>
</a>
edit:
if for some reason you can't wrap the image with an <a> you could assign and id to the image and then add an event listener for a click that will redirect you.
Thanks. I do understand how to use the href tag, but in the code above is seems like it should have a line by itself such as `` img5.a.href = 'attachments/DallasAddDuties.pdf'; but this didnt work. If I can use code like you have, where does it go in my code?
– K-Rod
Mar 27 at 19:04
beforeitem5.appendChild(img5);**you could try creating anaelement, saya5assigning anhrefto it. appendingimg5to that newa5element and appendinga5toitem5.
– Max
Mar 27 at 20:34
add a comment |
href is an attribute for the <a> tag. you can't add href to an image.
What you should do is create an <a> element assign the href you want to it and
append the img as a child of that <a> element.
<a href="whatever you want">
<img src=....>
</a>
edit:
if for some reason you can't wrap the image with an <a> you could assign and id to the image and then add an event listener for a click that will redirect you.
Thanks. I do understand how to use the href tag, but in the code above is seems like it should have a line by itself such as `` img5.a.href = 'attachments/DallasAddDuties.pdf'; but this didnt work. If I can use code like you have, where does it go in my code?
– K-Rod
Mar 27 at 19:04
beforeitem5.appendChild(img5);**you could try creating anaelement, saya5assigning anhrefto it. appendingimg5to that newa5element and appendinga5toitem5.
– Max
Mar 27 at 20:34
add a comment |
href is an attribute for the <a> tag. you can't add href to an image.
What you should do is create an <a> element assign the href you want to it and
append the img as a child of that <a> element.
<a href="whatever you want">
<img src=....>
</a>
edit:
if for some reason you can't wrap the image with an <a> you could assign and id to the image and then add an event listener for a click that will redirect you.
href is an attribute for the <a> tag. you can't add href to an image.
What you should do is create an <a> element assign the href you want to it and
append the img as a child of that <a> element.
<a href="whatever you want">
<img src=....>
</a>
edit:
if for some reason you can't wrap the image with an <a> you could assign and id to the image and then add an event listener for a click that will redirect you.
answered Mar 27 at 16:45
MaxMax
831 silver badge7 bronze badges
831 silver badge7 bronze badges
Thanks. I do understand how to use the href tag, but in the code above is seems like it should have a line by itself such as `` img5.a.href = 'attachments/DallasAddDuties.pdf'; but this didnt work. If I can use code like you have, where does it go in my code?
– K-Rod
Mar 27 at 19:04
beforeitem5.appendChild(img5);**you could try creating anaelement, saya5assigning anhrefto it. appendingimg5to that newa5element and appendinga5toitem5.
– Max
Mar 27 at 20:34
add a comment |
Thanks. I do understand how to use the href tag, but in the code above is seems like it should have a line by itself such as `` img5.a.href = 'attachments/DallasAddDuties.pdf'; but this didnt work. If I can use code like you have, where does it go in my code?
– K-Rod
Mar 27 at 19:04
beforeitem5.appendChild(img5);**you could try creating anaelement, saya5assigning anhrefto it. appendingimg5to that newa5element and appendinga5toitem5.
– Max
Mar 27 at 20:34
Thanks. I do understand how to use the href tag, but in the code above is seems like it should have a line by itself such as `` img5.a.href = 'attachments/DallasAddDuties.pdf'; but this didnt work. If I can use code like you have, where does it go in my code?
– K-Rod
Mar 27 at 19:04
Thanks. I do understand how to use the href tag, but in the code above is seems like it should have a line by itself such as `` img5.a.href = 'attachments/DallasAddDuties.pdf'; but this didnt work. If I can use code like you have, where does it go in my code?
– K-Rod
Mar 27 at 19:04
before
item5.appendChild(img5);** you could try creating an a element, say a5 assigning an href to it. appending img5 to that new a5 element and appending a5 to item5.– Max
Mar 27 at 20:34
before
item5.appendChild(img5);** you could try creating an a element, say a5 assigning an href to it. appending img5 to that new a5 element and appending a5 to item5.– Max
Mar 27 at 20:34
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55382370%2fwhat-is-the-function-to-add-a-link-to-a-graphic-in-javascript-under-document-cre%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What happened when you tried a href?
– Robert Columbia
Mar 27 at 16:41