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 trialDharma Teegala
4,401 Pointsgetting 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
4,817 PointsMake the 'h1' text value equal to the 'input' value -
$('h1').text( $('input').val() );
Jenny Veens
10,896 PointsHi 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();
Dharma Teegala
4,401 PointsThanks, Jenny
Dharma Teegala
4,401 PointsDharma Teegala
4,401 PointsThanks, Jade, your code worked perfectly.
Nick Davies
7,972 PointsNick Davies
7,972 PointsCould 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
4,401 PointsDharma Teegala
4,401 PointsIt is selecting the H1 tag [$("h1")] and printing the Text [.text] value of the input box [( $('input')] value [.val() );]