Forum:Header Links

This adds a padlock icon to every header in the content area, anything with the  class. An example might be Talk:AjaxRC. When clicked it alters the url to target that specific header using it's id, allowing you to copy/paste the url for whatever use you might have, be it linking to a certain section of your talk page, or avoiding having to type out a lengthy header id yourself. This works on pretty much every wiki, as the class seems to exist in every skin I've tested it in.

I realise this is much shorter in jQuery, where it works, but I wanted to use this as a way to learn native javascript. When it runs, it throws up the error Uncaught TypeError: Object mw-headline has no method 'getElementsByTagName', except I'm not using getElementsByTagName. The code works if you remove the anonymous function wrapper, but I'm not really sure why it's doing this. I ran it through jslint and jshint and came up with nothing.

Does anyone know why it's breaking?