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 trialRob Szopinski
9,818 PointsWhy is code only working when chaining methods?
I am following along with Treasure and double-checking, triple-checking that my code is the same. I will create the const variable and then call the variable later on and I am not getting the intended action. However, when I chain the methods, then my code starts working.
For example: This doesn't work:
const $secureLinks = $('a[href^="https://"]')
$secureLinks.addClass('secure');
This works:
const $secureLinks = $('a[href^="https://"]').addClass('secure');
Is this okay? Am I going to run into problems later with hard-coding or the like? Is there a setting on my browser that I need to look into. I had issues with using the download attribute earlier and saw that need to change privacy settings.
Thanks in advance!
1 Answer
KRIS NIKOLAISEN
54,971 PointsI pasted your code:
const $secureLinks = $('a[href^="https://"]')
$secureLinks.addClass('secure');
into app.js for this video's workspace. And I can see the links styled with the css. In inspecting the elements with developer's tools I can see the class was added. So I'm not sure what you are seeing.