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

Page is not updated - JQuery

Hi, I am trying to write a JavaScript program using JQuery that gets the text from some inputs elements and then write it to the page in a specific div.

when i using the script i see the page updated for one second and then it disappear.

var $post = $("<div class='post'></div>");

//bind the click method to the button

$("button").click(function(){

//assign the text in the input tags to variables
var updater_Name = $("input#name").val();
console.log(updater_Name);
var update_Date = $("input#date").val();
console.log(update_Date);
var last_Email_From = $("input#from").val();
console.log(last_Email_From);

//append the text to the "post" div
var paragraph = "<p class='bold'>Update Name: " + updater_Name + "</p>";
paragraph += "<p class='bold'>Date of update: " + update_Date + "</p>";
paragraph += "<p class='bold'>Last Email From: " + last_Email_From + "</p>";

$post.prepend(paragraph);

//appending it to "status" div
$(".status").append($post);

});

1 Answer

Steven Parker
Steven Parker
243,656 Points

:point_right: The update remains on the page for me.

I had to guess at the HTML to go with this script, but when I push the button, the update appears and remains on the screen. If I push the button additional times, I get another copy of the update text for each push. I'm using Chrome.

You might try posting the actual HTML and the CSS (if there is any) in case the problem is not with the script itself.

And FYI: You don't need "input#id" as a selector, just "#id" will do since there can be only one element with a specific id on the page.

tnx for your answer! i succeeded!