Reputation: 2108
I have the following code
$('#txtEditor').select(function (e) {
var start = e.target.selectionStart;
var end = e.target.selectionEnd;
selText = $('#txtEditor').val().substring(start, end);
});
<asp:TextBox ID="txtEditor" runat="server" TextMode="MultiLine" Width="500px" Height="500px" Font-Size="Large"></asp:TextBox>
I want to apply some style (colour it or make it bold or ittallic etc) only to the selected text (after selection) in the textbox. In selText
Im getting the selected string. But I couldn't find any event or function which will apply style only to the selected string in the textbox.
Upvotes: 3
Views: 1441
Reputation: 673
HERE IS THE COMPLETE SOLUTION...SUDHA
http:// js fiddle .net/ sandeepvirani/ mzays/
remove space between
Upvotes: 2
Reputation: 46559
To change the color of the selection part of a text on a page, use the CSS ::selection
pseudo-element.
See MDN documentation.
Note however, that
If you want to change some text inside a paragraph or something, you can use Javascript to quickly put the whole of the selection inside a new element, a span
or something, and then apply properties to the span
. However, if it's text in a textbox, you're out of luck, as you can't add child elements to an input
.
Upvotes: 0