Parameters required to reconstruct Range object creation

118 views Asked by At

I am doing a simple thing but facing various challenges along with it .All I wanna do is to store all required range object parameters inorder to reconstruct user selection. Currently I am storing id of start and endContainer and start and endOffset.But these params seems to be not enough as in case user selection spans to any childNodes within the start/endContainer its offset is calculated relative to that childNode and not start/endContainer id. So can anyone help me to figure out what all or extra params I would need to unqiuely identify my selection i.e nextSibling ,previousSibling of container etc ??

My current code for regenration of range object here is :-

function buildRange(startOffset, endOffset, startContainerId, endContainerId){

    var startContainer = document.getElementById(startContainerId);    
    var endContainer = document.getElementById(endContainerId);
    // create the range    
    var range = document.createRange();   
    range.setStart(startContainer.firstChild, startOffset);
    range.setEnd(endContainer.firstChild, endOffset);

    return range;
}
0

There are 0 answers