Why IE doesn't detect events on dinamically created elements?

E

equalium

Hello I am creating div elements on the fly with javascript:
....
this.closeButton = document.createElement('div');
this.closeButton.setAttribute('id', this.name+ 'Close');
this.closeButton.setAttribute('class', 'closeButton');
this.closeButton.setAttribute('onclick', "anyFunction()");
this.closeButton.className="closeButton"
me.windowControls.appendChild(me.closeButton);
....
My first problem was that elements didn't reflect the class attributes
in IE although in Firefox worked fine. I solved this with:
"this.closeButton.className="closeButton"".

But now I have the same problem with the "onclick" event. In Firefox
works OK but IE doesnt detect the click although I can see that the
"outputHTML" is OK.

Does anybody know how to solve this?
 
M

Michael Winter

On 03/04/2006 17:40, (e-mail address removed) wrote:

[snip]
My first problem was that elements didn't reflect the class
attributes in IE although in Firefox worked fine. I solved this with:
"this.closeButton.className="closeButton"".

Yes, that's because IE's implementation of the setAttribute method is
broken. Don't use it.

this.closeButton.id = this.name + 'Close';
this.closeButton.className = 'closeButton';
this.closeButton.onclick = anyFunction;

Or:

this.closeButton.onclick = function() {
/* ... */
};

Also, please don't use tabs on Usenet. Replace them with spaces -
preferably no more than four per level.

[snip]

Mike
 
E

equalium

Thank you very much. I´ll remember about the tabs too.
Greetings from Barcelona.

Carlos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top