2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by softDeveloper
0

You could try this code (it will require jQuery)

$('#click').click(function(){
    var range = window.getSelection().getRangeAt(0);
    var selectionContents = range.extractContents();
    var span = document.createElement("span");
    span.style.color = "red";
    span.appendChild(selectionContents);
    range.insertNode(span);
    
    
    alert(range);
    
});​

<p>Some text</p>
<button id="click">Click</button>​
0

Hi thanks!

I need to know the Caret Character Offset, and I need the tabs and \n \r to know the exact position of the selection

0

I have a text kept in MySQL database. I need to do certain operations in the database. And the data is displayed on an iframe. So I when I select text in the iframe the position doesn't correspond to the position in the data base. I think it might be the \r that is not recognised.. or some \t or \n, but whenever there is a newline the position doesn't match

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.