Ian, See the docs on how to develop a jQuery Plugin. http://docs.jquery.com/Plugins/Authoring.
However, since your code applies to each instance of a given class and not specific elements it already appears to do what you want. For example I changed your form to have two inputs and gave the second one a maxlength of 40 for fun. I didn't change any JS code and both text inputs reflected remaining characters correctly. As long as you use that label > input > span structure and give the input class="word_count" you can reuse that code. <form action="" method="post"> <div class="input"> <label for="field1">Text:</label> <input type="text" name="field1" id="field1" maxlength="50" class="word_count" /> <span class="counter"></span> character(s) available </div> <!-- New Text Input here --> <div class="input"> <label for="field2">Text:</label> <input type="text" name="field3" id="field1" maxlength="40" class="word_count" /> <span class="counter"></span> character(s) available </div> </form> On Mar 10, 5:42 pm, IanR <i...@ianroke.co.uk> wrote: > I have got some codehttp://pastebin.com/mc99132cwhich counts how > many characters have been entered in a textbox and subtracts it from > the maxlength to show how many characters are left. > > If I add a new textbox I don't want to copy and paste the code down > and rename the variables so is there a way of navigating the DOM tree > to change just the element currently being edited? > > Cheers, Ian.http://pastebin.com/mc99132c