Is it possible to append a button with a id to a div and then give it a mouseclick event later in the code? I was trying it out and it wouldn't work.

html:

    <body>
        <input type="button" id="button" value="Click me"/>
        <div id="add"></div>
    </body>

js:

$('#button').click(function() {
    $('#add').append('Hi, I am a button. <input type="button" id="new_button"');
});

$('#new_button').click(function() {
    alert('Hello');
});

I don't have the technical words, but you essentially use a parent/container as an event handler container (what?). I've set up a jsFiddle to demo. Hope it helps.

jsFiddle

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.