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
Brad Ames
2,378 PointsJQuery Basics > Getting a Value Code Challenge Help
I'm at a complete loss for this challenge. Here's the code challenge:
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!
//Select the input for the title for blog post. var $titleInput = $("#title");
//Select the preview h1 tag var $previewTitle = $("#titlePreview");
// Every second update the preview var previewTimer = setInterval(updatePreview, 1000);
function updatePreview(){
//Get the user's input
var titleValue;
//Set the user input as the preview title.
$previewTitle.text(titleValue);
}
So far I've understood just about everything in the JavaScript track but the JQuery course has left me confused for the most part. I've been stuck for a bit on this so any help will be appreciated.
Thanks in advance!
3 Answers
Juan Pablo Pinto Santana
15,719 PointsHi,
For getting the user's input using jQuery, is as easy as this (I'm assuming that your input field has an id title):
var titleValue = $('#title').val();
In your case, you could also write:
var titleValue = $titleInput.val();
Happy coding!
Juan Pablo Pinto Santana
15,719 PointsGlad I could help!
The way you add pretty code in a post is by using the markdown syntax. If you look closely, at the bottom of this textarea you can click on the link Markdown Cheatsheet. Use it as a guide to use markdown when posting questions and answers.
Cheers!
bevinwg
5,196 PointsI can't make sense of this or get this to work at all... I'm not even sure where I should be answering though I believe it is towards the end of the code
Brad Ames
2,378 PointsBrad Ames
2,378 PointsThanks for the help! By the way, how do you add pretty code like that in a post?