Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 259
webwrks Avatar asked Feb 13 '11 01:02

webwrks


1 Answers

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

should do it.

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

like image 98
jAndy Avatar answered Oct 27 '22 19:10

jAndy