Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


TzeYang Chew
TzeYang Chew
12,039 Points

Hi, I am stuck at adding class to my a tag from it's own id in javascript without jquery.

Hi, I am stuck at adding class to my a tag in javascript without jquery. It seem the matchingHeaderLink is point to the id of that a tag , but how do i create a class from that id? This is the error that i got below, Uncaught TypeError: Cannot create property 'className' on string '#our-beginning-link'

createPageSectionsWaypoints() {
    var that = this;
      item =>
        new Waypoint({
          element: item,
          handler: () => {
            let matchingHeaderLink = item.getAttribute("data-matching-link");
            matchingHeaderLink.className = "is-current-link";
<nav class="primary-nav primary-nav--pull-right">
              <a href="#our-beginning" id="our-beginning-link">Our Beginning</a>
              <a href="#features" id="features-link">Features</a>
              <a href="#testimonials" id="testimonials-link">Testimonials</a>

1 Answer

Well first of all i cant see in your index.html "data-matching-link", but if you want to select element with id and then give it a class name it should look like this >> "document.getElementById("myDIV").classList.add("mystyle");"