Alerts: Hide Parent Element

by Kevin Pliester

HTML

<div>
    <button type="button" class="close">
        X
    </button>
    <p>
        This is a simple Text.
    </p>
</div>
<div>
    <button type="button" class="close">
        X
    </button>
    <p>
        This is a simple Text.
    </p>
</div><div>
    <button type="button" class="close">
        X
    </button>
    <p>
        This is a simple Text.
    </p>
</div>

CSS

div {
    font-family: arial;
    margin: 15px;
    padding: 15px;
    border: 2px solid #ddd;
}
div button {
    float: right;
}

JavaScript

$(function() {
    $(".close").click(function() {
        $(this).parent().fadeOut(200);
        return false;
    });
});