Hi John, I think what you want is event.target

$("li.selectable").click(function(e){console.log(e.target)});

<http://docs.jquery.com/Events_%28Guide%29>

I'm so happy I bookmarked that page because I can't find a link to it
anywhere (not even on Google!). Is it old/new?

Brian.

On 3/13/07, John Cotton <[EMAIL PROTECTED]> wrote:

Thanks Karl.

However, that doesn't give me what I'm after...:)

A little more explanation. This is my pseudo-HTML

<li class="selectable">
        content content content
        <a href="##1">some link</a>
        content content content
        content content content
        <img src="##" />
        content content content
        content content content
        content content content
        content content content
        <a href="##1">some link</a>
</li>

Clicking on any element within this block will trigger the event. But I
want
to know if the <A> or <IMG> elements were clicked.

Your suggestion returns me "li" regardless of where I click.

Thanks again.

John


>Date: Tue, 13 Mar 2007 11:45:11 +1100
>From: "Karl Rudd" <[EMAIL PROTECTED]>
>Subject: Re: [jQuery] Reference to the element that triggered the
>event
>
>To: "jQuery Discussion." <discuss@jquery.com>
>Message-ID:
><[EMAIL PROTECTED]>
>Content-Type: text/plain; charset=UTF-8; format=flowed
>
>You don't actually need the * at the start of the selector, it's
>implicitly there.
>
>In the click function, to work out what has been clicked, you can do:
>
>var tag = this.nodeName.toLowerCase();
>
>Tag should be the tag name.
>
>Karl Rudd
>
>On 3/13/07, John Cotton <[EMAIL PROTECTED]> wrote:
>>
>>
>> Sorry if this is a really thick question, but I've hunted for over an
hour
>> on the website/Google/anywhere to find this and am getting nowhere.....
>>
>> I have the following code:
>>
>> $("*.selectable").click( function(e) {
>> $(this).toggleClass("selected");
>>
>> saveCookie($(this).attr("id"),
>> $(this).attr("class").indexOf("selected"));
>> });
>>
>> which works fine.
>>
>> But I want to know which element within *.selectable was actually
clicked
>> (eg an anchor, an image etc).....
>>
>> How do I do that?
>>
>> Thanks in advance
>>
>> John
>>
>>
>> --
>> No virus found in this outgoing message.
>> Checked by AVG Free Edition.
>> Version: 7.5.446 / Virus Database: 268.18.9/719 - Release Date:
12/03/2007
>> 08:41
>>
>> _______________________________________________
>> jQuery mailing list
>> discuss@jquery.com
>> http://jquery.com/discuss/ <http://jquery.com/discuss/>

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.9/719 - Release Date: 12/03/2007
08:41




_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to