Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


How to get the text string from a form to append as a <li>

I had to remove the triangle brackets for the li, since it hide the text when I tried using them.

I have a form with a submit button.

input class="text_box" type="text"/ button class="submit">Submit</button

I'm trying get the text from the form to append as a li when you click the submit button after entering text.

I was able to append li manually, but haven't figured out how to do this from the form.

$(".messages").append("liTest test1/li"); $(".messages").append("liTest test2 /li");

I have been able to trigger manual append when a user clicks submit, but can't figure out how to get the text from the textbox?

$(".submit").click(function (){ $(".messages").append("liYO/li");})

I could really use some help with this

1 Answer

Dave McFarland
Dave McFarland
Treehouse Teacher

To retrieve the value of a form field using jQuery you first select the form field then retrieve its value. In your example you have a text field with a class of text_box, so you can retrieve its value like this:


You might want to use an ID instead of a class on this element -- if you have more than one item on the page with the class text_box you could end up selecting text from the wrong text field.