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 trialAziz Kemal HOSCAN
Full Stack JavaScript Techdegree Graduate 16,113 PointsNeed help on solving jquery
It seems fine to me. I am getting element by its ID and use Jquery val(); Can not see the problem. Please help
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<h2 class="profile-name">Treasure Porth</h2>
<p class="profile-text">I am a web developer!</p>
<label>Change name:<input id="name-input" type="text"></label>
<button>Change</button>
<script
src="jquery-3.2.1.min.js"></script>
<script src="app.js"></script>
</body>
</html>
$('button').click(function() {
const newName = document.getElementById('name-input').val();
});
2 Answers
Dimitar Dimitrov
11,800 PointsYou are using mixed code to select the element. 1st. Your are using JavaScript to select the element -document.getElementById('name-input') 2nd. You are using Jquery method to get the value -val()
The challenge ask you to use only Jquery to select the element and get the value. in that case your code should look like this : ** var newName = $('#name-input').val();**
$('#name-input') is Jquery way to select things in the DOM, and document.getElementById('name-input') is one of the methods you can use in JavaScript to select DOM elements
So remember : $('#name-input') - Jquery document.getElementById('name-input') - JavaScript
And as i said the challenge ask you to use Jquery methos to complete it
Aziz Kemal HOSCAN
Full Stack JavaScript Techdegree Graduate 16,113 PointsOhh I see now. Thank you for the help Dimitrar!