Button append(), click function no response?

HTML:

<ul>
<li class='li">
<button type="button" id="<?php htmlout($replierid); ?>"  name="report" >

script:

$(document).ready(function() {
	$("button[name='report']").click(function() {
		alert('aaa');
        });
});

script end

script:

	     var li = ..
	    $(".li").append(li);
            $(li).append(the same button);

script end

the new buttons’ css, and every part of its html looks fine, however their click function is not available, does anyone know what causes this problem?

Hm… I ran a fiddle and everything seems to be working:

I see some syntax errors on the HTML part and I wonder if they are making the click method not get executed.

Wrap that li class with either single or double quotes only.

The button element needs to be closed.


Also, I didn't get the last part. Where is the following snippet supposed to be in the code? Is this also causing an error?

I saw the click me button, but actually my problem is when I append more buttons, the new buttons’ click function is not available.
I tried to use live() function like this:

	$("button[name='report']").live("click",function() {

        });

it made all the buttons’ click function unavailable.

I used on(), the new buttons’ click function is still not available

it’s done, by using
$(document).on(“click”,“button[name=‘report’]”,function(){

thank you though.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.