I'm trying to develop a script that will select elements within an
html page, kind of like a select-all script, but I want it to be "select-some"
The code I have so far is below, however, looping through the array of divs, it will only select the latter in the array. Through research I've concluded that I may somehow be able to workaround this using properties that are available to set the start and end position of the text range, however, I have no clue whatsoever how to use these
- Code: Select all
<html>
<head>
<script language="javascript">
function copySeperate(multipleID) {
multipleID = multipleID.split(",");
var i;
for(i in multipleID)
copySel(multipleID[i]);
}
function copySel(tagID){
refNode = document.getElementById(tagID);
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(refNode);
range.select();
//range.execCommand("Copy");
} else if (window.getSelection) {
var range = document.createRange();
range.selectNodeContents(refNode);
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
}
}
</script>
</head>
<body>
<div id="d1">This is div 1, I want to select this</div>
<div id="d2">This is div 2, I dont wanna select this</div>
<div id="d3">This is div 3, I want to select this</div>
<input type="button" value="1 and 3" onClick="copySeperate('d1,d3')" />
</body>
</html>