Vishal Vishal - 3 months ago 12x
jQuery Question

why autofocus does not work on input element

Here is my HTML:

<table id="tbl">
<tr id="tx"><td><input type="text"/></td><td><input type="text" class="last" /></td></tr>

Here is my jQuery:

$("#tbl").on("blur", ".last:last", function(){
$("#tbl").append('<tr><td><input type="text" autofocus/></td><td><input type="text" class="last" /></td></tr>');

As you can see in the above mentioned code, I am trying to append a row to the table when last cell of last row loses focus. The above code works fine, but now I want to focus the first cell of newly added row, when it is created. So, I would like to ask that why html5
does not work in my case?

Here is the link to my jsfiddle


I have modified your script this works fine.

$("#tbl").on("blur", ".last:last", function(){
    $("#tbl").append('<tr><td><input type="text"  class="focus_this" autofocus /></td><td><input type="text" class="last" /></td></tr>');