title: How to access array item within a class in javascript
body: <p>I am using an open source js library <a href="http://cesiumjs.org" rel="nofollow">Cesium</a>.  In this js a class is defined as a container with empty array [].  A push is used to add to this array.  The HTML display this whole container as a canvas.  I want to add a tool tip using jquery for each item of the array, but don't know how to do it.  I am able to add a tool tip for the container, but not the items within its container.<br>
  In the below code, class "cesium-timeline-tracks" is the one I am interested in.</p>
  
  <p>Please help. Below is the snipet of the code:</p>
  
  <p>Javascript file: </p>
  
  <pre><code>    function Timeline(container, clock) {
      container = getElement(container);
  
      this.container = container;
  
      var topDiv = document.createElement('div');
      topDiv.className = 'cesium-timeline-main';
      container.appendChild(topDiv);
      this._topDiv = topDiv;
  
      this._topDiv.innerHTML = '&lt;div class="cesium-timeline-trackContainer"&gt;' +
      '&lt;canvas class="cesium-timeline-tracks" width="10" height="1"&gt;' +
      '&lt;/canvas&gt;&lt;/div&gt;&lt;div class="cesium-timeline-bar"&gt;&lt;/div&gt;&lt;div class="cesium-timeline-needle"&gt;&lt;/div&gt;&lt;span class="cesium-timeline-ruler"&gt;&lt;/span&gt;';
  
      this._trackContainer = this._topDiv.childNodes[0];
      this._trackListEle = this._topDiv.childNodes[0].childNodes[0];
      this._timeBarEle = this._topDiv.childNodes[1];
      this._needleEle = this._topDiv.childNodes[2];
      this._rulerEle = this._topDiv.childNodes[3];
      this._context = this._trackListEle.getContext('2d');
  
      this._trackList = [];
      this._highlightRanges = [];
  </code></pre>
  
  <p>Each item in the array is added using push:</p>
  
  <pre><code>Timeline.prototype.addTrack = function(interval, heightInPx, color, backgroundColor) {
      /* EN added parameter id*/
      var newTrack = new TimelineTrack(interval, heightInPx, color, backgroundColor);
      this._trackList.push(newTrack);
      this._lastHeight = undefined;
      this.resize();
      return newTrack;
  };
  </code></pre>
  
  <p>To add an item, I just need to call timeline.addTrack(...);
  Below is how I use it for the cesium-timeline-tracks class, but I want to use for the item I have in the array _trackList.  Please help.</p>
  
  <pre><code>    $(document).ready(function() {
      $(".cesium-timeline-tracks").attr("title", "This is a tooltip for the timetracks.");
      $(document).tooltip({
          position: {
          my: "left bottom-20",
          at: "left top"
          }
      });
  });
  </code></pre>
  
  <p>Implement Ted's suggestion, but still does not show for each item, only the whole container.  Below is the code.  Note that timeline variable was created previously which is a timeline container(not shown in code).  I tried viewer.timeline._trackList, but that caused the tool tip to disappear all together.</p>
  
  <pre><code>$(document).ready(function() {
       //$(".cesium-timeline-tracks").attr("title", "This is a tooltip for the timetracks.");
      $.each(viewer.timeline, function (index, element) {
          $(element).attr("title", "tooltip for " + index);
          $(element).tooltip ({
              position: {
              my: "left bottom-20",
              at: "left top"
              }
          });
      });
  });
  </code></pre>
  
  <p>Changed viewer.timeline to viewer.timeline._trackList in .each, got errortype "d.addEventListener is not a function" in jquery-1.11.0.min.js.  The console shows index 0 as [object Object].</p>
  
  <pre><code>$(document).ready(function() {
      $.each(viewer.timeline._trackList, function (index, element) {
        console.log("****** the index " + index + " is " + element + ".");
  $(element).attr("title", "tooltip for " + index);
      $(element).tooltip ({
          position: {
                    my: "left bottom-20",
              at: "left top"
              }
          });
      });
  });
  </code></pre>
  
  <p>Output on console: the index 0 is [object Object].</p>