First of all, there are multiple question like this, but none of them explain my question, thus don't mark this as duplicate.
Don't tell how to achieve index 0, but, explain with example why I am getting 1 instead of 0 for 1st element?
Following is my code:
<?php
echo "<div class='container'>
<table class='table'>
<tr><th>mobile no.</th><th>app user name</th><th>expiry date</th></tr>
";
$q="SELECT d,c,m,n,a FROM asdf;";
$s=$link->prepare($q);
$s->execute();
$rs=$s->FetchAll();
foreach($rs as $r){
echo"
<tr>
<td><input type='hidden' class='hdn' value='".$r['d']."'/>+".$r['c'].'-'.$r['m']."</td>
<td>".$r['n']."</td>
<td>
<input class='cl_xpr' type='datetime-local' step='1' value='".date('Y-m-d\TH:i:s', strtotime($r['a']))."'/>
<input type='button' class='clbtnxpr' value='set this date'>
</td>
</tr>
";
}
echo"
</table>
";
?>
I get 1 with following code for button element (which is wrong):
$('.clbtnxpr').click(function(){
var vx=$(this).index();
alert(vx);
});
and I get 0 with following code for button element (which is correct):
$('.clbtnxpr').click(function(){
var vx=$('.clbtnxpr').index(this);
alert(vx);
});
More over, if i use following code for datetime-local element, I get correct index, i.e. 0
$('.cl_xpr').click(function(){
var vx=$(this).index();
alert(vx);
});
Please explain, why?
Don't give different methods to achieve index 0, rather, explain 'why this behavior?'