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


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");"