If you actually create a function reference instead of passing an anonymous
function, they will not be duplicated.

var fn = function(e) { alert('in textfield'); };

$('input.text').bind('focus', fn);


In the near future, once jQuery 1.1.3 is released, you would be able to use
the behavior plugin and it would automagically bind the events to new
elements as they are added. It would look like this:

$('input.text').behavior('focus', function() { alert('in textfield'); });

Then whenever a new element that matches that selector is added, it will
bind the event to it.

You can find the behavior plugin here (requires jQuery Rev 1845+):
http://brandonaaron.net/jquery/plugins/behavior/

--
Brandon Aaron

On 5/31/07, John R <[EMAIL PROTECTED]> wrote:


I have a table with rows of input fields that is dynamic in that the
user can add / remove rows.  I'm trying to trigger a function whenever
the user clicks in any of the fields, so for example I use this:

$("input.text").focus( function() { alert("In textfield"); } );

After a row is dynamically added, I need to reapply this so the new
rows fields will trigger the function as well, but if I just use that
line again then the original rows get triggered twice.

So, I'm trying to figure out how to filter out all the fields that
already have a focus event attached.  Basically, how do I say "Give me
all input.text's that don't have an onfocus set?

Thanks
John


Reply via email to