Textara selection

Benchmark created by Marcin on


Preparation HTML

<script>
  var b0 = document.createElement('BUTTON');
  document.body.appendChild(b0);

  var t1 = document.createElement('TEXTAREA');
  t1.innerHTML = "This is a messgge T1";
  document.body.appendChild(t1);

  var t2 = document.createElement('TEXTAREA');
  var txt2 = "This is a messgge T2";
  t2.innerHTML = txt2;
  document.body.appendChild(t2);

  var t3 = document.createElement('DIV');
  t3.contentEditable = true;
  var txt3 = "This is a messgge T3";
  t3.innerHTML = txt3;
  document.body.appendChild(t3);
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
select()
t1.select();
b0.focus();
ready
selectionStart
t2.focus();
t2.selectionStart = 0;
t2.selectionEnd = txt2.length;
b0.focus();
ready
createRange
var userSelection = window.getSelection(); // W3C default, an extra branch would be necessary if you want to support IE
var theRange = document.createRange();
theRange.setStart(t3, 0);
theRange.setEnd(t3, 1);
userSelection.addRange(theRange);
b0.focus();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Marcin on
  • Revision 2: published by Marcin on