Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  3] [ 1]  / answers: 1 / hits: 15649  / 12 Years ago, wed, september 19, 2012, 12:00:00

I'm trying to use appendChild within Javascript to create a link that has a onClick attribute. I can't seem to make it work or find how to do this simple task.



var link=document.createElement(a);
link.appendChild(document.createTextNode(Link));
link.href = '#';
link.onclick = 'loadScript()';
document.body.appendChild(link);

More From » appendchild

 Answers
48

You have to change



link.onclick = 'loadScript()';


by



link.onclick = loadScript;


DEMO


[#83008] Tuesday, September 18, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aubriea

Total Points: 641
Total Questions: 118
Total Answers: 101

Location: French Southern and Antarctic Lands
Member since Fri, Jan 6, 2023
1 Year ago
;