2

I have this code.

   jQuery(document).ready(function () { 
        if (navigator.appName == "Microsoft Internet Explorer") {
            $("label img").each(function (i) {
              $(this).click(imageClikced);  
            });
        }
    });

   function imageClikced(img) {
        alert(img.type);
    }

in alert box I am getting img.type as click. How should I pass the image to the imageClikced function as parameter.

Thanks for any help.

1
  • 1
    I'm not entirely clear on what you're trying to do, but inside the imageClicked function, this will be a reference to the clicked element. Commented Aug 1, 2012 at 9:06

2 Answers 2

2

The context object of an event handler (this) is the element it self so do this

function imageClikced() {
   alert(this);
}
Sign up to request clarification or add additional context in comments.

Comments

2

The first argument to a jQuery event handler is the jQuery event object, which has a property type that tells the type of the event that was fired.

You can refer to the image from .currentTarget of the event object:

function imageClikced(e) {
    alert(e.currentTarget);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.