Select Text jQuery

jQuery(".category-short-code").click(function () {
   selectText(jQuery(this).attr('id'));
});

function selectText(containerid) {
   if (document.selection) {
      var range = document.body.createTextRange();
      range.moveToElementText(document.getElementById(containerid));
      range.select();
   } else if (window.getSelection) {
      var range = document.createRange();
      range.selectNode(document.getElementById(containerid));
      window.getSelection().addRange(range);
   }
}