JQuery create list item from user input on click

Hi, I need some help. See my code below. Thanks in advance for any help.

$('#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>
+5
source share
2 answers
$('#btn_createList').click(function(){
    $('.ul_current').append($('<li>', {
         text: $('#input_listName').val()
    }));
});

must do it.

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

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

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

+1
source

All Articles