locked
event handling using javascript

    Question

  • hello,i am trying to develop a windows store app using javascript in visual studio.

    i have created a button.

    var button = document.createElement("button");
        button.innerHTML = "next";
        button.id = "next";    
        

    i want to generate an onclick event for this button.

    i used button.addEventListener("click",function) ,but it is not working.

    i also tried document.write("<input type=button value=next onclick="+func()+"/>").

    Tuesday, January 28, 2014 11:22 PM

Answers

  • Hi dumbleduck9,

    Try this:

                var button = document.createElement("button");
                button.innerHTML = "next";
                button.id = "next";
                button.onclick = function()
                {
                     // your function inside
                }
                document.body.appendChild(button);
    

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, January 29, 2014 1:22 AM
    Moderator