tags:

views:

217

answers:

4
$("a.close").click(function() {
    var id = $(this).attr("id");
    alert(id);
    $(this).parents("div.venue:first").fadeOut("Fast");
    return false;
});

Any ideas why the alert isn't correctly popping up the current divs ID?

Final code, thanks below for pointing my stupid error

var id = $(this).parents("div.venue:first").attr("id");
+1  A: 

Because your selector is working on an anchor:

$("a.close")

I'm guessing you mean the div after your alert, try this:

$("a.close").click(function() {
    var id = $(this).attr("id");
    alert($(this).parents("div.venue:first").attr('id'));
    return false;
});
karim79
A: 

The element you are trying to get the id for is an a not a div.

Craig
A: 

You're showing the id of the <a> element, not a div

Philippe Leybaert
A: 

If you want the parent DIV's id, you'll need to traverse up to the parent before you get the attribute.

var id = $(this).closest('div').attr('id');
tvanfosson