MediaWiki:Common.js: Difference between revisions

From NARA
Jump to navigation Jump to search
(try and remove white space on firefox using javascript.)
 
m (try some different js)
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
// Remove whitespace tags using JS. The CSS-based approach seems to work fine on Chromium-based browsers, but not very well on Firefox.
// Remove whitespace tags using JS. The CSS-based approach seems to work fine on Chromium-based browsers, but not very well on Firefox.
window.onload = function() {
window.onload = function() {
   var paras = document.querySelectorAll(".mw-parser-output p");
   var paras = document.querySelectorAll('.mw-parser-output p');
   for (var i = 0; i < paras.length; i++) {
   for (var i = 0; i < paras.length; i++) {
     if (paras[i].childNodes.length === 1 && paras[i].childNodes[0].nodeName === "BR") {
     if (paras[i].childNodes[0].nodeName === 'BR') {
       paras[i].parentNode.removeChild(paras[i]);
       paras[i].remove();
     }
     }
   }
   }  
}
}

Latest revision as of 07:10, 19 April 2023

/* Any JavaScript here will be loaded for all users on every page load. */

// Remove whitespace tags using JS. The CSS-based approach seems to work fine on Chromium-based browsers, but not very well on Firefox.
window.onload = function() {
  var paras = document.querySelectorAll('.mw-parser-output p');
  for (var i = 0; i < paras.length; i++) {
    if (paras[i].childNodes[0].nodeName === 'BR') {
      paras[i].remove();
    }
  } 
}