Reputation: 4212
I'm trying to create an element(div) on keyup of the space key (key-code 32). And also append the value of input as text in the new created div. This is what I have so far:
$(input).live('keyup', function(e){
if (e.keyCode == 32) {
var q = $(input).val();
var div = $('<div/>');
div.append(q);
}
});
It doesn't work. Here is an example: JsBin
Upvotes: 0
Views: 861
Reputation: 48793
Try something like this:
$('input').live('keyup', function(e){
if (e.keyCode == 32) {
var q = $('input').val();
var div = $('<div/>');
div.append(q);
$('body').append(div);
}
});
Upvotes: 1