Reputation: 2699
With this function I want to submit data (res_id) to a script and fadeout the div by it's id (using variable pos), the script is executed but the div won't fade out. Why is that?
$('.remove_resort').click(function() {
pos = $(this).attr("id");
rem_res();
});
function rem_res() {
$.get("/snowreport/request/remove.php", {
res_id: pos
}, function(data1) {
pos.fadeOut("slow");
});
}
Upvotes: 0
Views: 119
Reputation: 10338
You're storing pos = $(this).attr("id")
, which is a string, not a jQuery object. What your original code is doing is trying to call "somestring".fadeOut(), which won't work. If you keep a reference to the jQuery object for the element and call fadeOut on that, it should fade out.
Let's rewrite this code so that it does what you're after, is a little cleaner and more obvious:
$('.remove_resort').click(function() {
rem_res(this);
});
function rem_res(element) {
var $element = $(element),
id = element.id;
$.get("/snowreport/request/remove.php", { res_id: id }, function(data) {
$element.fadeOut("slow");
});
}
Upvotes: 0
Reputation: 342635
pos
contains the ID string, so you need $("#" + pos).fadeOut("slow")
Upvotes: 1
Reputation: 174957
pos
is outscoped. You should pass it as an argument to the function.
$('.remove_resort').click(function() {
pos = $(this).attr("id");
rem_res(pos);
});
function rem_res(pos) {
$.get("/snowreport/request/remove.php", {
res_id: pos
}, function(data1) {
pos.fadeOut("slow");
});
}
Upvotes: 0