views:

75

answers:

2

hey, sorry if this is pretty vague.im happy to provide any further information should it be needed.

Im working on a webpage which uses the jquery change() function to perform updates on the page with regard to the users input, for example change the color of a div depending on what the user enters.Each form entry is part of the class "formitems".Any time anything of this class changes it fires the update to the page.

However, i would like to show a loading icon beside the specific form item that the user has changed.I know i could set a different change function for each "formitem" member but this would be too inefficient.Is there a way to determine the id of which "formitem" member has triggered the change?

In simple terms,i know which class did it,i just need to know which member of the class did.

As i said i realise this may be vague, so im happy to answer any questions.

+2  A: 

In the context of the change callback function, "this" is the element that triggered the event:

$('.formitems').change(function(){
  var id = $(this).attr('id');  // or simply this.id;
});

Check this example.

CMS
Just tried this, it worked perfectly.thanks a lot
themaddhatter
A: 

Not possible as change events do not bubble so you cannot use event delegation. Therefore you are left with attaching individual change events for each element.

redsquare