Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
ASPX File:-

JavaScript
<script type="text/javascript" language="javascript">
        $(document).ready(function(){
$('#<%=txtsms.ClientID%>').html($('#<%=txtsms.ClientID%>').html().replace('V1',"<span style='color:#FF0000;'>" + "A1" + "</span>"));
 });
</script>



VB
if textbox txtsms.text=V1

O/p on I.E:- txtsms.text= A1

O/p on Chrome:- txtsms.text=<span style='color:#FF0000;'>A1</span>
Posted
Updated 16-Jun-14 21:25pm
v7
Comments
Kornfeld Eliyahu Peter 16-Jun-14 7:20am    
By looking at your sample output it seems that Chrome behaves right and IE wrong...Or did I missed something?
[no name] 16-Jun-14 8:48am    
txtsms is textbox & i want A1 in red colour which is working on IE but it not working on Chrome

Try this simple one:
XML
<script type="text/javascript" language="javascript">
function changeCol(txt) {
    $(txt).css('color', 'red');
}

html:
XML
<asp:textbox id="txtsms" runat="server" clientidmode="Static" text="V1" onblur="javascript:changeCol(this);"/></asp:textbox>
 
Share this answer
 
v2
Comments
[no name] 16-Jun-14 9:17am    
but i want to change colour selected text only not all text
for example

textbox txtsms.text = Roll no. V1
then textbox txtsms.text=Roll no. A1 (with A1 in red colour)
Schatak 16-Jun-14 9:22am    
Oh i got you ....let me edit my solution for that
[no name] 24-Jun-14 8:21am    
Schatak please find solution......
[no name] 24-Jun-14 9:21am    
See this link- https://www.youtube.com/watch?v=8MeNU1CEhlY
Recently I ran into similar problem where Html() was returning empty in chrome. I fixed it by changing the call to .val(). Possibly you to are having same issue.
 
Share this answer
 
Comments
[no name] 16-Jun-14 6:52am    
thanks for Solution but i used this before it is not working
Your approach is very wrong - you have to learn to use your tools while developing for the web...
JavaScript
$(document).ready(function() { 
  $('#<%=txtsms.ClientID%>').css('color', '#FF0000');
});
http://api.jquery.com/css/[^]
 
Share this answer
 
Comments
[no name] 16-Jun-14 9:01am    
but i want to change colour selected text only not all text

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

  Print Answers RSS


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