createElement not work

F

fidokomik

I'm trying to add new tags into document using createElement()
function but
this not work. Tested in FF2 and IE6.

Simple example is here http://web.practisoft.cz/samples/jstest.html

Buttons enclosed in first div are created in html code and work as
expected.

Buttons in second div are created by createElement() and
appendChild()
functions and not work.

Buttons in third div are created by inserting innerHTML into div and
this
work.

Can anybody tell me what I do wrong?
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your
mail from
another non-spammer site please.)

Please reply to <petr AT practisoft DOT cz>
 
M

Martin Honnen

fidokomik said:
I'm trying to add new tags into document using createElement()
function but
this not work. Tested in FF2 and IE6.

Simple example is here http://web.practisoft.cz/samples/jstest.html

Buttons enclosed in first div are created in html code and work as
expected.

Buttons in second div are created by createElement() and
appendChild()
functions and not work.

If you want to provide an onclick handler you need to assign a function
object and not a string so change

var but=document.createElement('button');
but.onclick="alert('" + k + "')";

to

var but=document.createElement('button');
but.onclick= new Function("alert('" + k + "')");
 

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,007
Latest member
obedient dusk

Latest Threads

Top