Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / July 2008



Tip: Looking for answers? Try searching our database.

createElement not work

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
fidokomik - 04 Jul 2008 13:49 GMT
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>
Martin Honnen - 04 Jul 2008 13:59 GMT
> I'm trying to add new tags into document using createElement()
> function but
[quoted text clipped - 8 lines]
> 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 + "')");

Signature

    Martin Honnen
    http://JavaScript.FAQTs.com/

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.