Youss
Youss

Reputation: 4212

Create element and append value of input

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

Answers (2)

Engineer
Engineer

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

Kokizzu
Kokizzu

Reputation: 26818

i have fixed it for you http://jsbin.com/uyagak/2

Upvotes: 1

Related Questions