In JQuery, how we can pass entire $(this) to a functions? Possible?
A:
The $(this) element is exposed in most jQuery event operations. You can add a functional parameter to your jQuery handlers.
$("a.someClass").live("click", function(e) {
// $(this) is a reference to the same <a> element.
var link = $(this);
doSomethingToLink(link);
});
Jarrett Meyer
2010-03-12 14:24:43
Completely unrelated and on top of that, wrong: `e` is **not** a reference to the anchor, it is an **Event** Object.
Marko Dumic
2010-03-12 14:33:11
sorry, you're right. fixed my example
Jarrett Meyer
2010-03-12 15:19:27
A:
Your question isn't very specific, but maybe you want something like this:
$("a.myLinkClass").click(
function(){
$(this).addClass('myClickedLinkClass'); // 'this' refers to the anchor element that was clicked
}
);
inkedmn
2010-03-12 14:25:36
+3
A:
Um, it depends on what you are passing, but have you just tried the following:
function do_something_cool(jquery_link_object) {
/* I do something awesome! */
}
$('a.my_link_class').click(function() {
do_something_cool($(this));
});
This will pass the clicked link to the do_something_cool method.
Topher Fangio
2010-03-12 14:26:22