Dr.Ajay Kashyap

Dr.Ajay Kashyap

  • 1.1k
  • 521
  • 276.5k

How to Change Text Color Using Java Script In MVC

Dec 7 2016 2:24 AM
Hello....Plz Help 
 i want to change the color of div="cnt" which Show Remaining Character. if Character More The 28 Then want Color In Green Other Wise by default Red
 
 HTML CODE:-
 
<div class="col-md-4">
@Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control"} })
@Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })
<div id="cnt" style="color:red;"></div>
</div>
 
JAVASCRIPT:- 
 
$("#Title").keyup(function () {
var lenCount = document.getElementById('Title');
var count = 145 - lenCount.value.length;
document.getElementById('cnt').innerHTML = count + ' ' + 'Character Remaining';
 I DO This But It Not Work:-
 
if (count >= 28) {
document.getElementById("cnt").style.color = "#ff0000";
}
 
 
if (count == 145) {
$("#cnt").html('');
}
});
 
 

Answers (1)