function slugify(str) {
str = str.replace(/^\\s+|\\s+$/g, ''); // trim leading/trailing white spaces
str = str.toLowerCase(); // convert string to lowercase
str = str.replace(/[^a-z0-9 -]/g, '') // remove any non-alphanumeric characters
.replace(/\\s+/g, '-') // replace spaces with hyphens
.replace(/-+/g, '-'); // remove consecutive hyphens
return str;
}
display: none after opacity (etc) transition:
// add stylesheet in the document <head>
function addCss(fileName) {
const head = document.head
const link = document.createElement("link")
link.type = "text/css"
link.rel = "stylesheet"
link.href = fileName
head.appendChild(link)
}
// add non-breaking space character before last word
function replaceLastSpace(input){
const outputArr = input.split("")
outputArr[input.lastIndexOf(" ")] = " "
return outputArr.join("")
}
You can use the removeProperty method to remove a specific inline CSS property defined in the style attribute.
https://codepen.io/matuzo/pen/OJyQgmr
The nullish coalescing operator (??) only returns its right-hand side operand when its left-hand side operand is null or undefined.