lexeme lexeme - 3 months ago 17
Javascript Question

Operating with several items selected with JQuery

If selecting one item

$('.item')
is it possible to reference it inside event-handler using
$(this)
?


  1. Howcome I reference items if I will use multiple items selection:

    $('#form1 td.item, #form2 td.item').event-handler(...{ })

  2. I need to fire an event when for example
    #form1 td.item
    or
    #form2 td.item
    losts its focus. How do I do that?



EDIT

So will
blur()
fire up on any of selector items:

$('#form1 td.item, #form2 td.item').blur(function() {
// something's there
});


?

Answer

If you attach an event handler to multiple items, each item will have the handler attached and will trigger it independently, so $(this) will refer to whichever item triggered the event