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
Joe Sleiman
5,921 Pointsit's the same right?
in this video he used this : $option.val($anchor.attr("href")); then he used a " prop()" so i conclude that this 2 lines are the same : we can use this 2 right??? $option.val($anchor.attr("href")); $option.prop("value",$anchor.attr("href"));
1 Answer
Iain Simmons
Treehouse Moderator 32,305 PointsKind of, but val() is specifically made for getting and setting the value of a form element.
From the jQuery docs for .prop():
"Properties generally affect the dynamic state of a DOM element without changing the serialized HTML attribute. Examples include the value property of input elements, the disabled property of inputs and buttons, or the checked property of a checkbox. The .prop() method should be used to set disabled and checked instead of the .attr() method. The .val() method should be used for getting and setting value."
It's also much clearer in your code, for other developers, or for when you refer back to it.
Joe Sleiman
5,921 PointsJoe Sleiman
5,921 Pointsokay thanks man
Iain Simmons
Treehouse Moderator 32,305 PointsIain Simmons
Treehouse Moderator 32,305 PointsIf my answer helped, please mark it as 'Best Answer' so others will know this question is closed/solved. :)