JavaScript Uncaught ReferenceError: $$ is not defined

I'm trying to programmatically create a pie chart in hopes of turning it into a React Component to reuse. Basically I need a pie chart that is clickable and each slice expands into a whole pie when clicked. I'm trying to follow this tutorial to making pie charts and at the bottom, I have a piece of JS that I tried to test out. I ended up getting Uncaught Reference Error: $$ is not defined. Here's a screenshot of error message.

enter image description here

My understanding is that this is not jQuery and is simply Vanilla JS. I'm not sure if this is true. I imported jQuery via a CDN and still got the same error. I read this SO post and I'm thinking $$ is simply a kind of variable name notation.

This is the code I have in index.html, nothing groundbreaking.

<body>
  <div class="pie">20%</div>
  <div class="pie">60%</div>
  <script src="https://code.jquery.com/jquery-2.2.4.js" integrity="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI=" crossorigin="anonymous"></script>
  <script type="text/javascript">
    $$('.pie').forEach(function(pie) {
      var p = parseFloat(pie.textContent);
      var NS = "http://www.w3.org/2000/svg";
      var svg = document.createElementNS(NS, "svg");
      var circle = document.createElementNS(NS, "circle");
      var title = document.createElementNS(NS, "title");
      circle.setAttribute("r", 16);
      circle.setAttribute("cx", 16);
      circle.setAttribute("cy", 16);
      circle.setAttribute("stroke-dasharray", p + " 100");
      svg.setAttribute("viewBox", "0 0 32 32");
      title.textContent = pie.textContent;
      pie.textContent = '';
      svg.appendChild(title);
      svg.appendChild(circle);
      pie.appendChild(svg);
    });
  </script>
</body>

What's causing the error? Am I misunderstanding? Is the tutorial I'm following outdated/wrong? Thank you!

Answer:1

Include the following:

function $$(selector, context) {
  context = context || document;
  var elements = context.querySelectorAll(selector);
  return Array.prototype.slice.call(elements);
}

According to the author, Lea Verou, she mentions:

in the book the definition of $$() is given in the introduction, but since this is an excerpt, it doesn’t include that.

Answer:2

From tutorial you mention in your question i got something that will help you.

enter image description here

Also, you need to wrap your code in,

$(function(){....});

As you mention jquery in your tags.

Hope this helps.

Answer:3

Currently I am working on Learning React and Redux. I have found a boilerplate, and I am working on looking through all of the example code. My problem is I don't completely understand what a lot of ...

Currently I am working on Learning React and Redux. I have found a boilerplate, and I am working on looking through all of the example code. My problem is I don't completely understand what a lot of ...

I have my custom script for map into my webpage,but it no have point mark for exactly ubication: <script> /* Map */ (function () { "use strict"; if (document.getElementById("map")) { ...

I have my custom script for map into my webpage,but it no have point mark for exactly ubication: <script> /* Map */ (function () { "use strict"; if (document.getElementById("map")) { ...

  1. mark point google maps

I have a link with an hover effect. When you hover it, the text become red and underlined. When you click it, the text stay red and underlined. My problem is that once you clicked on the link, the ...

I have a link with an hover effect. When you hover it, the text become red and underlined. When you click it, the text stay red and underlined. My problem is that once you clicked on the link, the ...

  1. hover click event jquery
  2. mouse hover click jquery
  3. hover after click jquery
  4. hover instead of click jquery
  5. remove hover on click jquery
  6. change hover to click jquery
  7. combine hover and click jquery
  8. jquery hover click conflict
  9. jquery hover click mobile
  10. hover and click function jquery
  11. convert hover to click jquery
  12. jquery hover click toggle
  13. disable hover after click jquery

I'm trying to retrieve a single result from a multi-dimensional array and then push that result into each object contained within an object array. Here is my code; var data = { "questions": ["...

I'm trying to retrieve a single result from a multi-dimensional array and then push that result into each object contained within an object array. Here is my code; var data = { "questions": ["...

  1. push property into object javascript
  2. push property into object
  3. push new property into object javascript
  4. javascript push property into array
  5. javascript push object property into array