if(document.createRange)//Firefox, Chrome, Opera, Safari, IE 9+
{
range = document.createRange();//Create a range (a range is a like the selection but invisible)
- range.selectNodeContents(contentEditableElement);//Select the entire contents of the element with the range
+ range.selectNodeContents(contentEditableElement.childNodes[0]);//Select the entire contents of the element with the range
range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
selection = window.getSelection();//get the selection object (allows you to change selection)
selection.removeAllRanges();//remove any selections already made
else if(document.selection)//IE 8 and lower
{
range = document.body.createTextRange();//Create a range (a range is a like the selection but invisible)
- range.moveToElementText(contentEditableElement);//Select the entire contents of the element with the range
+ range.moveToElementText(contentEditableElement.childNodes[0]);//Select the entire contents of the element with the range
range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
range.select();//Select the range (make it the visible selection
}
if(document.createRange)//Firefox, Chrome, Opera, Safari, IE 9+
{
range = document.createRange();//Create a range (a range is a like the selection but invisible)
- range.selectNodeContents(contentEditableElement);//Select the entire contents of the element with the range
+ range.selectNodeContents(contentEditableElement.childNodes[0]);//Select the entire contents of the element with the range
range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
selection = window.getSelection();//get the selection object (allows you to change selection)
selection.removeAllRanges();//remove any selections already made
else if(document.selection)//IE 8 and lower
{
range = document.body.createTextRange();//Create a range (a range is a like the selection but invisible)
- range.moveToElementText(contentEditableElement);//Select the entire contents of the element with the range
+ range.moveToElementText(contentEditableElement.childNodes[0]);//Select the entire contents of the element with the range
range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
range.select();//Select the range (make it the visible selection
}
if(document.createRange)//Firefox, Chrome, Opera, Safari, IE 9+
{
range = document.createRange();//Create a range (a range is a like the selection but invisible)
- range.selectNodeContents(contentEditableElement);//Select the entire contents of the element with the range
+ range.selectNodeContents(contentEditableElement.childNodes[0]);//Select the entire contents of the element with the range
range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
selection = window.getSelection();//get the selection object (allows you to change selection)
selection.removeAllRanges();//remove any selections already made
else if(document.selection)//IE 8 and lower
{
range = document.body.createTextRange();//Create a range (a range is a like the selection but invisible)
- range.moveToElementText(contentEditableElement);//Select the entire contents of the element with the range
+ range.moveToElementText(contentEditableElement.childNodes[0]);//Select the entire contents of the element with the range
range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
range.select();//Select the range (make it the visible selection
}