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

I can't find my mistake - Getting a Value - jQuery Basics

I have tried multiple different things, but always the same error comes up: 'Bummer! When I type in to the input "Hello World" I get ".' I don't really understand what is going wrong. Here is my code: Here is my code:

//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); var $anchor = $(this); $titleIinput.val($anchor.attr("h1")); }

Can anyone point out my mistake? Thank you in advance.

1 Answer

Marc Schultz
Marc Schultz
23,356 Points

Your code:

function updatePreview(){
  //Get the user's input
  var titleValue;
  //Set the user input as the preview title.
  $previewTitle.text(titleValue);
  var $anchor = $(this);
  $titleIinput.val($anchor.attr("h1")); // almost, but the $anchor variable is not required
}

The solution:

function updatePreview(){  
  //Get the user's input
  var titleValue = $titleInput.val();
  //Set the user input as the preview title. 
  $previewTitle.text(titleValue);
}