rationalboss
rationalboss

Reputation: 5389

jquery event could not be bound

show('<div class="alignLeft"><div id="ownerinfo"></div><br /><h3>Where will the document go?</h3><select id="dest"><option value="">-- select destination --</option><option>'+this.DESTINATIONS.join('</option><option>')+'</option></select><h3>Notes</h3><input type="text" id="notes" size="70" /><p><button id="regbtn">Register</button></p></div>','append',function(){
            $('#regbtn').click(function(){
                alert('ok');
            });
            alert($('#regbtn').click);
        });

The above is the code. show() is just a function that adds animation but executes third parameter after animation. It works with other functions. However, the problem is in $('#regbtn').click() -> I cannot seem to bind it. What could be the problem here?

I'm hoping that even if I don't upload the whole code you can help me figure it out. When i alert the .click, this is the output:

function (a,c){c==null&&(c=a,a=null);return arguments.length>0?this.bind(b,a,c):this.trigger(b)}

Upvotes: 2

Views: 216

Answers (1)

Tats_innit
Tats_innit

Reputation: 34117

Since you seem to be appending the element dynamically, so please try .on even to ping click event:

http://api.jquery.com/on/

Please lemme know if I missed anything!

script

 <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>

code

$('#regbtn').on('click',function(){
                alert('ok');
            });

or

   $(document).on('click','#regbtn',function(){
                    alert('ok');
                });

Upvotes: 3

Related Questions