Fix #1322

https://github.com/mybb/mybb/issues/1322
Also simplified the file a bit using chaining and variables so jQuery
won't have to look for selector multiple times for no reason.