Reputation: 2361
I have following problem. After clicking on text I want to changing this text with input. After insert value in this input and press ENTER I want to returning input value.
I using this code but not worked after click enter :( :
$(document).ready(function() {
$('.qty_new').click(function(){
$(this).replaceWith("<input class='newVal' value='' />");
return false;
$('.newVal').keypress(function(e){
var qty=$(this).val();
var code =null;
code = (e.keyCode ? e.keyCode : e.which);
if (code == 13){
alert('ratata');
}
});
});
<span class='qty_new'>100</span>
Thanks in advance !
Upvotes: 0
Views: 53
Reputation: 2343
please see my fiddle - code works fine
just get rid off return false;
$(document).ready(function() {
$(document).on('click','.qty_new',function(){
$(this).replaceWith("<input class='newVal' value='' />");
$('.newVal').keypress(function(e){
var qty=$(this).val();
var code =null;
code = (e.keyCode ? e.keyCode : e.which);
if(e.keyCode == 13) {
alert('You pressed enter! '+qty);
}
});
});
})
Upvotes: 1