webwrks
webwrks

Reputation: 11918

jQuery create list item from user input on click

Hi I am in need of some help. Please see my code below. Thanks in advance for any assistance.

$('#input_listName').keyup(function(){
var newList = $(this).val();

$('#btn_createList').click(function(){
    ('.ul_current').append().html(newList);
});
});
<input type="text"  id="input_listName"/>
<br/>
<button type="submit" class="btn_sendMessage" id="btn_createList">Create List</button>

<ul class="ul_current">
    <li>Item</li>
    <li>Item</li>
    <li>Item</li>
</ul>

Upvotes: 4

Views: 22059

Answers (2)

netdreamer
netdreamer

Reputation: 11

$('#btn_createList').click(function() {    
    $('.ul_current').append('<li>' + $('#input_listName').val());
});

Demo: http://jsfiddle.net/netdreamer/uvuUe/

Upvotes: 1

jAndy
jAndy

Reputation: 236022

$('#btn_createList').click(function(){
    $('.ul_current').append($('<li>', {
         text: $('#input_listName').val()
    }));
});

should do it.

Demo: http://www.jsfiddle.net/G8pbG/

Upvotes: 7

Related Questions