Event Class tidak jalan

ini sebagian script saya:

            $('.tambahKegiatan').on('click', function() {

                $.ajax({

                    type: 'POST',

                    url: 'function.php',

                    data: {

                        cek: 'tambahKegiatan'

                    },

                    success: function( respon) {

                        $(".tengah").append("<input type='submit' class='tombol' value='Tambah waktu                             bel ON'>");

                    }

                })

            })

            $(".tombol").click(function( e) {

                e.preventDefault();

                alert('ok');

            })

Ketika class tambahKegiatan dijalankan akan muncul submit button.

Ketika submit button diklik seharusnya menjalankan alert('ok').

Tapi mengapa alert tidak muncul ya?

Mohon pencerahan

avatar marc
@marc

2 Kontribusi 0 Poin

Dipost 2 tahun yang lalu

Tanggapan

Kode html nya juga gan sekalian di lampirkan juga, biar gampang tracking nys

1 Jawaban:

<div>ini sebagian script saya:<br><br>$('.tambahKegiatan').on('click', function() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp;$.ajax({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type: 'POST',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;url: 'function.php',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;data: {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cek: 'tambahKegiatan'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; success: function(<em>respon</em>) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(".tengah").append("&lt;input type='submit' class='tombol' value='Tambah waktu bel ON'&gt;");&nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>})&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br><br>$(".tombol").click(function(<em>e</em>) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; e.preventDefault();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; alert('ok');&nbsp; &nbsp; &nbsp; &nbsp;<br>})<br><br>Ketika class tambahKegiatan dijalankan akan muncul submit button.<br>Ketika submit button diklik seharusnya menjalankan alert('ok').<br>Tapi mengapa alert tidak muncul ya?<br>Mohon pencerahan</div>

avatar marc
@marc

2 Kontribusi 0 Poin

Dipost 2 tahun yang lalu

Login untuk ikut Jawaban