Click here to Skip to main content
15,886,632 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm writing an html editor control. I want to change css attributes of selected text of the content. I get the selectedcontent by window.getSelection(); What is the best way to make bold selected text, and to understand selected text is bold then to make it normal. Replace with required tags doesn't work. Since similar texts can be in content. It looks quite complicated to me. I'm looking for the best way to do it.
Posted
Comments
Krunal Rohit 13-Oct-15 6:55am    
did u try ::selection ?

-KR
kubibay 13-Oct-15 7:01am    
I don't think it is what i need.
Let's say; I need to make bold/unbold selected text from a content by a button.
The problem is if there are occurences of selected text how do I understand which one is selected?

1 solution

JavaScript
<pre lang="cs">$(document).on('selectionchange', function(e) {
            document.execCommand('bold');
    });


is the solution.

http://jsfiddle.net/XCb95/132/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900