Alerting works for me. However why would you add a class if you are redirecting to a new page?
$("#better a").bind('click', function() { $(this).addClass('active'); });
Two guesses:
Do you maybe have another element on your page with
id="better"
? ID is supposed to be globally unique, so the selector will only return one of them.Try making your click function return false, to keep the user from following the link. (Seems strange to add a class when the user is leaving the page, unless maybe the link opens in a new window.)
Try running the code at the bottom of the page right before the closing body tag or in a $(document).ready() function.
Using Firebug, you can use console.log() to write out to the javascript console to make sure the selector is actually returning elements. example: console.log($("#better > a").length)
If I understand what you're asking.. you want to end up with this?
<div id="better">
<a href="1.aspx" class="active">One</a>
<a href="2.aspx" class="active">Two</a>
<a href="3.aspx" class="active">Three</a>
</div>
If any link in that div was clicked, right? (you did say ALL anchor tags)... then use this:
$("#better").click(function() {
$(this).find('a').addClass('active');
return false;
});