Keep in mind that "this" refers to the element on which the event is
being handled, NOT the element that originated the event. See
http://www.quirksmode.org/js/events_order.html  for an explaination of
how events are captured and
http://www.quirksmode.org/js/events_properties.html for good measure.

Depending on what your needs are the following will give you the
element that originated the event:
$(document).ready(function() {
        $("td").click(function() {
                var targ;
                if (!e) var e = window.event;
                if (e.target) targ = e.target;
                else if (e.srcElement) targ = e.srcElement;
                if (targ.nodeType == 3) // defeat Safari bug
                        targ = targ.parentNode;
                var id = targ.id
});

John's approach is probably what you are looking for. I'm just helping
with a complete answer.

Adam

On 10/20/06, John Resig <[EMAIL PROTECTED]> wrote:
> Something like this:
>
> $(document).ready(function() {
>        $("td").click(function() {
>            var id = this.id;
>            // now do stuff with id!
>        });
> });
>
> --John
>
> > How do I get the id of the item which was just clicked?
> >
> > For instance, if a user clicks a <td> which has a specific id, how do I use
> > this id in my script?
> >
> > $(document).ready(function() {
> >         $("td").click(function() {
> >           // get the id of the table cell clicked
> >           // use the id in a script
> >         });
> > });
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to