createElement not work

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fidokomik

    createElement not work

    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

    #2
    Re: createElement not work

    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.cr eateElement('bu tton');
    but.onclick="al ert('" + k + "')";

    to

    var but=document.cr eateElement('bu tton');
    but.onclick= new Function("alert ('" + k + "')");


    --

    Martin Honnen

    Comment

    Working...