redho home | products | services

Programming Forums


Community for Java, PHP, Perl C, ASP and Python programmers
Thursday 21 November 2019 00:35

Ask your IT question here

range object



 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Programming Forums -> JavaScript forum
View previous topic :: View next topic  
Author Message
Jony
Enthusiastic Coder


Joined: 18 Mar 2005
Posts: 71
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:

<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><br /><br />
<div id="d2">This is div 2, I dont wanna select this</div><br /><br />
<div id="d3">This is div 3, I want to select this</div><br /><br />

<input type="button" value="1 and 3" onClick="copySeperate('d1,d3')" />
</body>
</html>

Reply with quote
 
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Programming Forums -> JavaScript forum


Dubai Forums - Expat Help | Vegan Forum | Java Programming | 3d Design Resources | 3d Forum | 3D Jobs | 3D Textures | Paris Forum | Europe Forum
Dubai Classifieds | Dubai Property | Jobs in Dubai | Free London Classifieds | Jobs in London UK

High Quality, Custom 3d animation and Web Design solutions Royal Quality Web Hosting Services Vegetarian and Animal Rights news

© 2018 RedHo