Replace Selected Text - JSFiddle

HTML

<script src="http://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.7.19/fabric.min.js"></script>
<canvas id="paper" width="400" height="400" style="border:1px solid #ccc"></canvas>

JavaScript

var canvas = new fabric.Canvas('paper');
canvas.setHeight(300);
canvas.setWidth(500);

var text = new fabric.Textbox('Sample Text', {
  left: 50,
  top: 100,
  fontFamily: 'arial',
  fill: '#333',
  fontSize: 50
});
canvas.add(text);

text.selectionStart = 0;
text.selectionEnd = 4;

text.setSelectionStyles({

});

var selectionStart = 0;
var selectionEnd = 4;
var lineIndex = 1;



  text.setSelectionStyles({
    textBackgroundColor: '#0F0'
  }, 2, 4)

canvas.renderAll();