title: FabricJS apply function only to certain types of object
body: <p>How can you target certain types of object on the FabricJS canvas.</p>
  
  <p>Such as iText objects only, shapes only or svg objects only.</p>
  
  <p>If we take iText for example I don't mean target one that says 'Hello' and over one that says 'Goodbye' but <strong>all</strong> iText objects and <strong>not</strong> shape objects.</p>
  
  <p>In the case of the demo below the mouse:down function should apply to iText and not the rectangle (baring in mind the rectangle may not always have a var rect).</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var canvas = this.__canvas = new fabric.Canvas('canvas');
  
  // Example function to apply to 1 type of object only
  canvas.on('mouse:down', function(e) {
      if (e.target) {
          if (!e.target.__corner) {
              e.target.toggle('flipX');
              canvas.renderAll();
          }
          e.target.__corner = null;
      }
  });
  
  // create a rectangle
  var rect = new fabric.Rect({
    left: 50,
    top: 50,
    width: 100,
    height: 50,
    angle: 20,
    fill: 'red'
  });
  // set rectangle gradient
  rect.setGradient('fill', {
      type: 'linear',
      x1: -rect.width / 2,
      y1: 0,
      x2: rect.width / 2,
      y2: 0,
      colorStops: {
          0: '#ffe47b',
          1: 'rgb(111,154,211)'
      }
  });
  canvas.add(rect);
  
  //create text
  var text = new fabric.IText('Hello World!',{
     top:100,
     left:200,
     textBackgroundColor: '#000',
     fontSize:30,
     fill: 'white',
     fontWeight: 'bold',
     textAlign: 'center',
  });
  canvas.add(text);
  
  canvas.renderAll();</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>#canvas { background-color:#f4f4f4; }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.7.9/fabric.js"&gt;&lt;/script&gt;
  
  &lt;canvas id="canvas" width="400" height="300"&gt;&lt;/canvas&gt;</code></pre>
  </div>
  </div>
  </p>