I am following aM1Ne
answer (the one with most vote)of this this thread for binding event, as i am generating multiple element dynamically
My js code looks like
$(document).on('click', ".myCheckBox" , function() {
//.....
});
Here myCheckBox
is the class that is assigned to all generated check box. Now i want the index of the clicked checkbox. I have tried
alert($(this).index());
inside. But it always shows 0
. Is there any way to get the index of clicked check box which contains the myCheckBox
class?
In HTML i Have a single check box
<input type="checkbox" name="" class="myCheckBox" >
and in a button and on its onclick
$("#clickAdd").click(function()
{
("#myDiv").append("<input type=\"checkbox\" class=\"myCheckBox\" >");
});