I’m trying to let an “a” tag focused after it has been created by an ajax call.
the code is the following:
<form method="post" id="submitrow">
<table>
<tr>
<td>
<input name="quantity" id="id_quantity" />
</td>
<td>$
<input name="price" id="id_price" />
</td>
<td><span id="add_row"></span>
</td>
</tr>
</table>
</form>
<script>
jQuery("#id_quantity").change(function () {
jQuery('#add_row').html('<a onclick="document.forms[\'submitrow\'].submit();" id="sbmbtn">click me</a>');
jQuery('#sbmbtn').focus(); // I want to focus the new link, it does not works
alert(jQuery('#sbmbtn').is(':focus')); // it should be True!
jQuery('#sbmbtn').live("keyup", function (e) {
if (e.keyCode == 13) {
alert('whoot whoot!');
}
});
});
jQuery("#id_quantity").focus();
</script>
It seems the DOM is not correctly updated after the html replacement. Maybe I have to replace the code in a different way?
I’ve create a fiddle with a simplified version of my code that reproduces the problem.
Thanks in advance for any hint provided! 🙂
Just set tabindex on a tag