JQuery / script cheatsheet

From TempusServa wiki
Revision as of 11:18, 6 September 2017 by old>Admin (→‎Selecting text for easy copying)
Jump to navigation Jump to search

Selecting text for easy copying

 var textNode = document.getElementById('IdOfNodeToBeSelected');
 if (document.selection) {
   var range = document.body.createTextRange();
   range.moveToElementText(textNode);
   range.select();
 } else if (window.getSelection) {
   var selection = window.getSelection();
   var range = document.createRange();
   range.selectNodeContents(textNode);
   selection.removeAllRanges();
   selection.addRange(range);	
 }