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

Alicja Dul
Alicja Dul
8,589 Points

my Chrome won't access jQuery

I have a problem with starting to work with jQuery. I get a warning message in the console: Uncaught TypeError: no access at jquery-3.1.1.min.js:2 at jquery-3.1.1.min.js:2

What am I doing wrong?

6 Answers

Can we see your code?

Alicja Dul
Alicja Dul
8,589 Points
<!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>
Alicja Dul
Alicja Dul
8,589 Points
console.log($('a').attr('href'));

$('button').on('click', function() {
  $('a')attr('href', 'https://teamtreehouse.com/library/accessing-and-modifying-attributes')
  console.log($('a').attr('href'));
});
Alicja Dul
Alicja Dul
8,589 Points

Those are the console warnings:

(unknown) Uncaught TypeError: no access at installGlobalHook (<anonymous>:2:20) at <anonymous>:53:6 installGlobalHook (anonymous) (unknown) Uncaught TypeError: no access at Object.<anonymous> (<anonymous>:2:3343) at webpack_require (<anonymous>:1:125) at Object.<anonymous> (<anonymous>:3:8341) at webpack_require (<anonymous>:1:125) at Object.<anonymous> (<anonymous>:1:27402) at webpack_require (<anonymous>:1:125) at Object.<anonymous> (<anonymous>:1:335) at webpack_require (<anonymous>:1:125) at <anonymous>:1:284 at <anonymous>:1:307 (anonymous) webpack_require (anonymous) webpack_require (anonymous) webpack_require (anonymous) webpack_require (anonymous) (anonymous) (unknown) Uncaught TypeError: no access at <anonymous>:1:46 (anonymous) jquery-3.1.1.min.js:2 Uncaught TypeError: no access at jquery-3.1.1.min.js:2 at jquery-3.1.1.min.js:2 at jquery-3.1.1.min.js:2 (anonymous) @ jquery-3.1.1.min.js:2 (anonymous) @ jquery-3.1.1.min.js:2 (anonymous) @ jquery-3.1.1.min.js:2

you missed a period between a and attr I think

$('button').on('click', function() {
  $('a').attr('href', 'https://teamtreehouse.com/library/accessing-and-modifying-attributes')
  console.log($('a').attr('href'));
});
Alicja Dul
Alicja Dul
8,589 Points

Thanks. Seems to work now