Difference between revisions of "JQuery / script cheatsheet"
Jump to navigation
Jump to search
old>Admin (Created page with " ==== Selecting text for easy copying ==== var textNode = document.getElementById('opusNode'); if (document.selection) { var range = document.body.createTextRange();...") |
old>Admin |
||
Line 2: | Line 2: | ||
==== Selecting text for easy copying ==== | ==== Selecting text for easy copying ==== | ||
var textNode = document.getElementById(' | var textNode = document.getElementById('IdOfNodeToBeSelected'); | ||
if (document.selection) { | if (document.selection) { | ||
var range = document.body.createTextRange(); | var range = document.body.createTextRange(); |
Revision as of 11:18, 6 September 2017
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); }