Mitarbeit willkommen! Bitte schau unter Hilfe:Benutzerkonto oder informiere Dich über Populus.Wiki.

MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus Populus DE
Zur Navigation springenZur Suche springen
Zeile 19: Zeile 19:
   
 
var thkOnLoadListener = function(){
 
var thkOnLoadListener = function(){
document.querySelector('#toc a:first-of-type').classList.add(className);
+
var firstA = document.querySelector('#toc a:first-of-type');
  +
console.log(firstA);
  +
if (firstA !== null) {
  +
firstA.classList.add(className);
  +
}
 
};
 
};
   

Version vom 16. Juli 2023, 12:13 Uhr

(function () {

const className = "selected";

var thkOnHashChangedListener = function(){
  var prev = document.querySelector('#toc a.' + className);

  if (prev !== null) {
    prev.classList.remove(className);
  }

  var curr = document.querySelector('#toc a[href="' + window.location.hash + '"]');
  if (curr !== null) {
    curr.classList.add(className);
  }
};

window.addEventListener("hashchange", thkOnHashChangedListener);

var thkOnLoadListener = function(){
  var firstA = document.querySelector('#toc a:first-of-type');
  console.log(firstA);
  if (firstA !== null) {
    firstA.classList.add(className);
  }
};

window.addEventListener("load", thkOnLoadListener);

})();