Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript jQuery Basics (2014) Creating a Mobile Drop Down Menu Getting a value

Dharma Teegala
Dharma Teegala
4,401 Points

getting a value

Take a look at the app.js and preview. The aim of this application is to show what the user types in to the input field and preview it in the H1 tag. Almost all the code is there, there's just one thing missing. Retrieving the value from the input. I forgot how to do it. Could you finish it for me? Thanks!

2 Answers

Jade Cook
Jade Cook
4,817 Points

Make the 'h1' text value equal to the 'input' value -

$('h1').text( $('input').val() );
Dharma Teegala
Dharma Teegala
4,401 Points

Thanks, Jade, your code worked perfectly.

Nick Davies
Nick Davies
7,972 Points

Could you explain what this is doing please? Is it, selecting the H1 tag [$("h1")] and saying the Text [.text] value should be the input box [( $('input')] value [.val() );]

Would this then only take the second (processed second) input value if there were two input fields?

Dharma Teegala
Dharma Teegala
4,401 Points

It is selecting the H1 tag [$("h1")] and printing the Text [.text] value of the input box [( $('input')] value [.val() );]

Jenny Veens
Jenny Veens
10,896 Points

Hi Dharma,

I think you could probably make use of jQuery's .val() method: http://api.jquery.com/val/

It will get the value of a specified element, or set the value of that element is one is passed in.

You'll probably want to do something like:

var textForH1 = $('input').val();