Back to top links in Mediawiki/Wikipedia
Back to top and search suggestions on Project:Support deskWikipedia:Back to top - WikipediaOr, if you have
Edit section disabled you can use
mw-headline to trigger the event (add in Common.js):
( function () {
var elems = document.getElementsByClassName('mw-headline'); // *** NOTE: ClassName may need to be 'mw-editsection' instead
for (i = 0; i < elems.length; i++) {
var span = document.createElement('span');
span.classList.add('ttop');
var link = document.createElement('a');
link.href = '#top';
link.appendChild(document.createTextNode('back to top'));
span.appendChild(document.createTextNode('['));
span.appendChild(link);
span.appendChild(document.createTextNode('] '));
elems[i].insertBefore(span, elems[i].firstChild);
}
});
Since I also added a style, you need to add the following in Common.css to have the text in a small size and right-aligned.
span.ttop {
float: right;
font-size: small;
}