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 trialisrar haque
118 Pointstrying same javascript function with JQuerry
// javascript code
const input = document.querySelector('input'); const button = document.querySelector('button'); const p = document.querySelector('p.description');
button.addEventListener('click', () => {
p.textContent = input.value + ':';
});
// jQuery code
$('button').click(function(){
var v = $('input').val();
if(v == ''){
alert("Enter Some Text In Input Field");
}else{
alert(v);
} $('p.description').html() = v.val();
});
1 Answer
Steven Parker
231,261 PointsAssuming that jQuery is being properly loaded, the problem is this line:
$('p.description').html() = v.val();
You can't assign something to a method call, but the way the "html" method works is that you give it the value you want used as an argument inside the parentheses. Also, the variable "v" represents the value and not the element, so it has no "val" method. Finally, if you want it to do the same job as the plain JavaScript code, you'll need to append a colon to that value:
$("p.description").html(v + ":");
And when sharing code on the forum, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. Or watch this video on code formatting.