• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Preferred method of adding JavaScript

I'm working on a custom bbCode for my forum and it will require a bit of JavaScript to be added. I know that using inline <script> tags is a big no no but I was curious as to the preferred method of adding a handlers to selectors when a page is loaded.

I found something similar to what I'm trying to do with http://xenforo.com/community/threads/creating-a-beautiful-looking-spoiler-tag.17083/ but I was hoping for more of an abstract rundown on adding JavaScript and how it fits into the already existing namespaced code.

TL;DR - How do I add new JS events in the proper manner? Is XenForo.register(selector, fn, event) the only way to do this?