Skip to content

Instantly share code, notes, and snippets.

@technomaz
technomaz / Regex Snippets.md
Last active April 17, 2019 18:08
Regex Snippets

Remove span tags from HTML

</?span[^>]*>

Replace Sitecore SPAN tags inside of anchors:

<span style="text-decoration: underline;">([^<>]+)</span>

$1

@technomaz
technomaz / window.load.js
Created July 16, 2020 17:38
Plain javascript alternative to jQuery ready() - window load
// loads later, so may be slow
window.addEventListener('load', functionName, false );
@technomaz
technomaz / dom-elements.js
Created July 16, 2020 17:58
DOM Get Element functions
// Get single element by ID
var el=document.getElementById('test');
// Get single element by class name
var el=document.getElementsByClassName('test')[0];
@technomaz
technomaz / dom-listeners.js
Created July 16, 2020 18:00
DOM event listener functions
// Add click listener
el.addEventListener("click", function() { alert('click'); }, false);
@technomaz
technomaz / ready-function.js
Last active June 3, 2021 14:45
Plain javascript alternative to jQuery ready() - readyState and DOMContentLoaded
// based on: https://www.techiediaries.com/javascript/pure-javascript-equivalent-or-alternative-to-jquery-ready/
// based on: https://stackoverflow.com/a/9899701/271985
function docReady(fn) {
if (document.readyState !== 'loading'){
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}