Volatire666
Programmer
- Nov 30, 2008
- 2
Here is the scenario: I have a textarea with text in it and I want to select/highlight predefined text within the textarea with a function. This code using ranges works with IE -
selectText = function(node, text)
{
var range = document.body.createTextRange();
range.moveToElementText(node);
range.findText(text);
range.select();
}
Firefox handles ranges completely differently and is not very well documented. I have got as far as creating a range which includes all the text in the textarea -
var range = document.createRange();
range.setStart(node, 0);
range.setEnd(node, 1);
I'm not sure where to go from here. Any further ideas on how to create a selection of text within a textarea?
selectText = function(node, text)
{
var range = document.body.createTextRange();
range.moveToElementText(node);
range.findText(text);
range.select();
}
Firefox handles ranges completely differently and is not very well documented. I have got as far as creating a range which includes all the text in the textarea -
var range = document.createRange();
range.setStart(node, 0);
range.setEnd(node, 1);
I'm not sure where to go from here. Any further ideas on how to create a selection of text within a textarea?