Aaah, :) That's a different kettle of fish. You'll want to look at the
event's "target" member.

If we use your "pseudo-HTML" and this code:

$(".selectable").click( function(e) {
  alert( e.target.nodeName.toLowerCase() );
});

If you click the image it should alert 'img'.

Note that if you click one of the "raw" text nodes inside the
.selectable the target will be the .selectable.

Karl Rudd

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