ready() is a replacement for window.onload and is therefore only intended to be used against document.
$(document.ready(){ // jquery code goes inside the ready()... // eg ..... $("textarea#MessageBody") .after("<input id=\"CharCounter\"/>") .each(function(){CharCounter(this);}) .keyup(function(){CharCounter(this);}); }); On Nov 5, 8:59 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > The following code works perfectly fine: > > 1. Checks if a certain textarea exists. > 2. Adds an input box straight after it. > 3. Counts the number of characters in the textarea either (a) when it > becomes available or (b) on the keyup event. > > $("textarea#MessageBody") > .after("<input id=\"CharCounter\"/>") > .ready(function(){CharCounter($('textarea#MessageBody'));}) > .keyup(function(){CharCounter(this);}); > > But when i replace the 3rd line with: > > .ready(function(){CharCounter(this);}) > > It ceases to work. > > How come? > > Thanks to anyone helping me understand this.