Mitch,

The following code would attach a "click" event to every "img" tag on the
page. When you click the image, you'll get an alert w/a message and the
source path to the image.

$("img").bind(
        "click",
        function (){
                alert("You clicked an image!\n\n" + this.src);
        }
);

Now, you could easily adjust the selector to just bind the behavior to
images that also have a class of "clickme":

$("img.clickme").bind(
        "click",
        function (){
                alert("You clicked an image!\n\n" + this.src);
        }
);

-Dan


________________________________________
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Mitchell Waite
Sent: Friday, July 20, 2007 1:43 PM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: Click to call a fuction?

Glen

Can you give me an example of how the syntax for this might work. I mean the
whole garbanzo. From what I get about using the ID approach each image has
to have a unique ID which means the function you want to call has to be
reproduced over and over.

Thanks

Mitch

From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Glen Lipka
Sent: Friday, July 20, 2007 9:02 AM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: Click to call a fuction?

Also, if its multiple images, you can give the images a class or find them
in any CSS way.
So if you can find the object, any object using CSS, then you can use that
in jQuery.

$("img").click...
$(" div.someContainer img").click...
$("img.classOfImage").click...
$("img:first").click //gets the very first one
$("img:even".click //gets every other one

Check out the "selectors" on the jQuery page...very powerful and fun stuff. 
http://docs.jquery.com/Selectors

Glen
On 7/20/07, Andy Matthews < [EMAIL PROTECTED]> wrote:
Easy to do what you want:
 
<img src="someimage.jpg" id="myImage">
 
$('#myImage').click(function(){
    alert('testing');
});

________________________________________
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Mitchell Waite
Sent: Friday, July 20, 2007 9:21 AM
To: jquery-en@googlegroups.com
Subject: [jQuery] Click to call a fuction?
Is there a way to call a jQuery function when someone clicks on an image
without making that image a hyperlink.
 
If that is the only way is there something you can put in the href to
eliminate the border that hyperlinks make.
 
Thanks
 
Mitch
 
PS I posted this as a question from Goofy last night and no one answered it.
Perhaps now that my status has been so graciously elevated and I am planning
a jQuery for Dummies book, someone might help me. Here is the previous
question
 
Why won't this work. It's so simple. I just want to call a function using
the on lick event. I want it to move a div called Panel.
 
I set up the function
 
                                function advmode() (
                                               
$("#Panel").SlideInRight(1000);
                                };
 
Then inside a table cell with an image for a button I have this simple link
 
                                <a href="#Javascript;"
onclick="advmode()"><img src="images/Advanced Search Button Wide_No.png"
width="250" height="25" />
 
I must be missing something really basic because this does not come close to
working. But this does:
 
                                <a href="#Javascript;"
id="PanelButtonOpen2"><img src="images/Advanced Search Button Wide.png"
width="250" height="25" />
 
                                $('#PanelButtonOpen2').click(function() {
                                $("#Panel").SlideOutRight(1000);
                                });
 
Thanks for any aid I am feeling very silly tonight.
 
Mitch
 


Reply via email to