Hello, excusme if the problem is easy but I really cannot find the solution. And this is my first post here - so if I make any mistakes - appologies.
Problem:
1) The script is appended to the page - kind of bookmarklet creating a div on the left side of the page. I want to make a list of links there that after clicking the link will execute a function.
2) As for the element to which I want to append the onclick is <a> element
Now the problem is that all looks all right but when i click the link with assigned function to onclick event the browser says xxx is not defined
The code looks like (just a piece and example - if needed more let me know):
After checking the code when executed we got:
i
<a id="a_item1" onclick="alert_fun ()" style="color: navy; text-decoration: none;">Unframe</a>
However the function cannot be called.
Any help or hints appreciated. Thank U.
Problem:
1) The script is appended to the page - kind of bookmarklet creating a div on the left side of the page. I want to make a list of links there that after clicking the link will execute a function.
2) As for the element to which I want to append the onclick is <a> element
Now the problem is that all looks all right but when i click the link with assigned function to onclick event the browser says xxx is not defined
The code looks like (just a piece and example - if needed more let me know):
Code:
function alert_fun () { alert ('ddd'); } var link = document.createElement('a'); link.setAttribute('id', 'a_item1'); link.setAttribute('onclick', 'alert_fun ()'); var _item1anchor_Ref = document.getElementById("a_item1"); _item1anchor_Ref.style.color = "navy"; _item1anchor_Ref.style.textDecoration = "none"; _item1anchor_Ref.innerHTML = 'Unframe'; (....)
After checking the code when executed we got:
i
<a id="a_item1" onclick="alert_fun ()" style="color: navy; text-decoration: none;">Unframe</a>
However the function cannot be called.
Any help or hints appreciated. Thank U.
Comment