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

JavaScript Introduction to jQuery Hello, jQuery! Accessing and Modifying Attributes

I'm not sure what I am doing wrong

I have been following along with this video and when I click on "Go somewhere else", it takes me to Google but doesn't log it in the console. Same with the link to Github. What am I missing? Here is my code:

DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <a href="https://www.google.com/">Go somewhere else!</a>
    <button>Change Destination</button>
    <script
  src="https://code.jquery.com/jquery-3.1.1.min.js"
  integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
  crossorigin="anonymous"></script>
  </body>
</html>
console.log($('a').attr('href'));

$('button').on('click', function() {
    $('a').attr('href', 'https://github.com/');
    console.log($('a').attr('href'));
});

2 Answers

Steven Parker
Steven Parker
231,269 Points

I think you're misunderstanding the JavaScript code.

This code doesn't intercept or alter the link function, so nothing will be logged when you click the link.

However, when you click the "Change Destination" button, it will log the new destination location that the link will be ready to take you to.

jason chan
jason chan
31,009 Points

Go somewhere else is HTML anchor tag.

Change destination is the button you create with jquery to go to github.