jQuery reduce number of listeners/events -


the below code works me need cleaned , simplified as possible, can help? in advance

$('#dealtemplatei18nmetatitle_en_au').keyup( function() {    var len = $(this).val().length;    if (len >= 32) {      $('#dealtemplatei18nmetatitle_en_au').css("background-color", "#ff3b3b").css("font-size", "16px").css("font-weight", "bold").css("color", "#ffffff");    } else {      $('#dealtemplatei18nmetatitle_en_au').css("background-color", "#82b548").css("font-size", "16px").css("font-weight", "bold").css("color", "#ffffff");    } }); 

i don't think can remove listeners or events (you have 1 , 1 need if you're watching keyup events). if going make changes js without changing markup, i'd go this: http://jsfiddle.net/mryga/

$("#dealtemplatei18nmetatitle_en_au").keyup(function() {     var el = $(this);     var len = el.val().length;     var bgcolor = len >= 32 ? "#ff3b3b" : "#82b548";      el.css({         "font-size": "16px",         "font-weight": "bold",         "color": "#ffffff",         "background-color": bgcolor     }); }); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -