By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,817 Members | 2,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,817 IT Pros & Developers. It's quick & easy.

createElement not work

P: n/a
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>
Jul 4 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
fidokomik wrote:
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 + "')");
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 4 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.