Href onlick does not work

I have the following code where when i use lnk.href = “javascript:save_group()”; work in IE but on firefox but when i try to use onclick, the click
does not repond either in IE or on FF. Can you please help me to fix it so that it works on both IE and FF?

var td3 = document.createElement(“td”);
var lnk = document.createElement(“a”);
//lnk.href = “javascript:save_group()”;
lnk.href = “#”;
lnk.onClick = “save_group()”;

Thanks for your help in advance.

Try using just the .click method instead as onClick is usually for HTML attribute events

Is it correct to turn the function into a string?

lnk.onclick = save_group;


I just tried the click method but that did not work.
//lnk.href = “javascript:save_group()”;
lnk.href = “#”; = “save_group()”;

The following method works in IE but not on FF:
lnk.href = “javascript:save_group()”;
//lnk.href = “#”;
// = “save_group()”;

Can you help me with a method that works in both IE and FF?

Thanks in advance.

Are you setting attribute values for HTML elements?

There are two problems with your original code:

lnk.onClick = "save_group()";

First, the event must be all lowercase.

Second, assigning a string to the event won’t do much good. Instead, assign a reference to the function you want to run instead.

lnk.onclick = save_group;

I would do it this way or another option is

link.onclick = function() {

I tried the following options:

Works in IE but not on FF:
lnk.href = “#”;
lnk.onclick = save_group;

works in IE but not on FF
var lnk = document.createElement(“a”);
//lnk.href = “save_group()”;
lnk.href = “#”;
lnk.onclick = function() {

Thanks for your help.

So there must be some other seemingly unrelated issue that’s causing it to fail in non IE browsers.

If you can link us to a test page that we can look at and diagnose, that would be of tremendous help to you.

what parent element are you assigning lnk to?

It would help if you posted all your js and html code or a link to a test page.