please see: http://jsfiddle.net/4Z4fQ/19/
consider the following html:
<a id="myElement" href="http://www.google.com/">
<img id="image" src="http://www.google.com/intl/en_com/images/srpr/logo3w.png" alt="google"/>
</a>
and the following script:
jQuery.fn.MyFunction = function (event) {
alert('My function was called');
alert(this.href);
};
$("#myElement").click(function (event) {
//some processing
$("#myElement").MyFunction(event);
});
without changing MyFunction, how do I change this line: $("#myElement").MyFunction(event); so I get the href to show in the alert?
The selector is right. But you must call jQuery's .attr() function to get the href attribute because this is a jQuery Object.
jQuery.fn.MyFunction = function (event) {
alert('My function was called');
alert(this.attr("href"));
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With