I have a page that may or may not have alerts like:

```
<div class="alert">Some alert</div>

```

And I am hiding them after 5 seconds with:

```
<script type="text/javascript">
$(document).ready(function () {

window.setTimeout(function() {
    $(".alert").fadeTo(1500, 0).slideUp(1500, function(){
        $(this).remove(); 
    });
}, 5000);

});
</script>

```

So I'm wondering, should I put the alert hiding function into my general functions that always executed when a page loads and even if there is no alert to hide? Or put it in the HTML code right below the actual alert div code so that it only happens when that alert shows?

The upside of the first option is that my code is more organized. The downside is that it may execute even if there is no alert.

The upside of the second option is that it only executes when the alert shows, but the downside is that the code is messier.

Which is better?