were is the element with alert being used as a css class name?? more important where is it in relation to where the script code is??
since you aren't wrapping that javascript in a function block this will run as the page is loading and if the element is after the script then it won't work.
this is why in jQuery you have:
$(document).ready(function(){
})