Sure it works, this is what $() was made for, why would you use * or # and then check if $chan is the active channel?