Perfect, that is what I needed! Thank you very much!

-Seth



Glen Lipka wrote:
> 
> Not sure if it makes a difference..but I think this would work too
> 
> $(document).ready(function() {
>       $("td").click(function() {
> 
>           var id = $(this).attr("id") <http://this.id/>;
>           // now do stuff with id!
>       });
> });
> 
> I guess this.id is shorter.  The interesting thing to me is to try and
> avoid
> IDs at all if possible.  jQuery makes this really easy.  So let's say you
> had the TD and you wanted to add a classname of the TR parent.  And get
> the
> value of the text inside it and replace it or whatever.
> 
> $(this).parents("tr").addClass;
> var originalText = $(this).text();
> $(this).empty();
> $(this).append("<span>" + someNewText + "</span>")
> 
> Anyway, the point is that it gives you the ability to think locally
> (relative) in the dom and make manipulations without accessing via ID. 
> The
> API is chock full of interesting things you can do to the node that was
> clicked $(this)
> Hope this wasnt a distraction. :)
> Glen
> 
> 
> On 10/20/06, Adam van den Hoven <[EMAIL PROTECTED]> wrote:
>>
>> 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/
>>
> 
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Get-element-ID-tf2483865.html#a6933469
Sent from the JQuery mailing list archive at Nabble.com.


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

Reply via email to