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
Ahmed Abdelaziz
5,929 PointsI understand almost 95% of the code except this part, Could anybody make it clear to me?
//I know how these methods work ,but i feel confused with "selected" and don't know why we apply prop() to $option. //Deal with selected options depending on current page
if($anchor.parent().hasClass("selected")) {
$option.prop("selected", true);
}
2 Answers
Jeff Pierce
18,077 PointsHi Ahmed.
It looks like you have two jquery elements ($anchor & $option) that have a relationship you need to act on programmatically.
if($anchor.parent().hasClass("selected")) { $option.prop("selected", true);
The $option element's selected property needs to be set to true because the $anchor's parent has the class "selected".
What might be confusing are the strings "selected". While the class could be any string such as hasClass("highlighted") or "chosen", the option element .prop (property) "selected" must be used to work as expected.
Ahmed Abdelaziz
5,929 PointsThanks a lot, Jeff :)
Jose Soto
23,407 PointsHi Ahmed. If Jeff's answer helped you out, please mark it as the best answer. This will help other community members find an answer to their questions quicker.
Thanks!