Reputation: 1747
I've created a table with a PHP foreach
loop; now I'm trying to replace the value inside td
with an input
when clicked.
$('#memberTable tr td').click(function(e){
$(this).html('<input type="text" id="" size="20" value=""/>');
});
The input style just blinks once on :focus
and then it loses focus.
Upvotes: 0
Views: 983
Reputation: 225263
Try focusing it manually:
var input = $('<input type="text" id="" size="20" value="" />');
$(this).empty().append(input);
input.focus();
Upvotes: 0
Reputation: 298532
You can make it focused with .focus()
:
$('#memberTable tr td').click(function(e) {
var $this = $(this);
$this.empty();
$('<input />', {
type: 'text',
id: '',
size: 20,
value: $this.text()
}).appendTo($this).focus();
});
Upvotes: 1