I write html and javascript:
$(document).ready(function(e) {
$('#btadd').click(function(e) {
$('#content').html('<span class="btnmsg"></span>' + $('#result').html());
$('.btnmsg')[i].click(function(e) {
alert('span ' + i);
});
i++;
});
});
var i = 0;
<input type='button' value='add' id='btnadd'>
<div id='content'></div>
On html code, I create a button
and a div
. When click on button
, on div
will add new element span.
I want that when click on span
, there will be a alert message. I don't want to use inline js (add onClick
to span
), because I write this addon for browser.
So I just want to write this event for span
in js only.
I write as above code, but nothing to see (no alert message). What can I do?