~/ is only for server side code like .NET controls can have that assigned for an url like on <asp:Hyperlink NavigateUrl="~/whatever.aspx"
it cannot be used in raw html, but in some cases you can use it with raw html like this:
<a href='<%= Page.ResolveUrl("~/whatever.aspx")%>'>My Link</a>
The advantage of ~/ is that it can resolve the applicaiton root correctly no matter if the site is a root level site or running in a sub folder/virtual directory whereas the html way / always resolves to the root of the web site not the virtual directory.
Usually I don't add script the way you did, I add it from code as in the article Adding Custom Javascript.
Hope that helps,
Joe