Does anybody know a way for matching Selection object with HTML dom elements based on something else than the element value?
Let's consider the table below:
123 | 246 | 345
456 | 123 | 567
The user wants to modify the first row by selecting it with mouse. In javaScript I can match the
window.getSelection().toString().split("\t")
with
document.getElementsByTagName("td")
to find thet selected cells. But for that matching I haven't found any other means than combining the element values (innerHTML). This will mean that all cells with the same value ( in the example the second column on the second line) become modified althoug not chosen. My code for reference:
function setAsNumeric(selection){
var allTds = document.getElementsByTagName("td");
var results = [];
var selArray = selection.toString().split("\t").join("\r\n").split("\r\n")
for ( var i = 0; i < selArray.length; i++ ) {
for ( var x=0; x < allTds.length; x++ ){
if ( allTds[x].innerHTML == selArray[i] ){
results.push(allTds[x]);
}
}
}
var n;
for (i = 0; i < results.length; i++){
n = document.createElement("td");
n.innerHTML = results[i].innerHTML;
n.className = "number";
results[i].parentNode.insertBefore(n, results[i]);
results[i].parentNode.removeChild(results[i]);
}
}