$(document).ready(function() {
function GetDeals() {
alert($(this).attr("id"));
}
$('.filterResult').live("click", function(event) {
GetDeals();
});
});
What do I need to pass as argument in function GetDeals()
so that I can manipulate with $(this)
?
Thanks in advance!
You could just use the function as your event handle:
$('.filterResult').live("click", GetDeals);
(please note, you don't use the ()
to call the function, so the function itself is being passed to the live()
function, not its result.
Or you can use Function.prototype.apply()
$('.filterResult').live("click", function(event) {
GetDeals.apply(this);
});
Above solution works and absolutely no issues with that. However I believe a better pattern here is :
$('.filterResult').live("click", function(event) {
GetDeals($(this));
});
function GetDeals(linkObj) {
var id = $(linkObj).attr("id");
console.log(id);
}
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