Executes all the code written inside the function, passed as a parameter, when the page is ready.
function whenPageIsReady(func) {
// If the page is not loading, it's ready.
if (document.readyState != 'loading') {
// Execute the func passed.
func();
} else {
// Wait for the Page to get Loaded and execute the func passed.
document.addEventListener('DOMContentLoaded', function(){
console.log("function called");
});
}
}
Add addEventListener
to the element
passed as the parameter.
function click(element, func) {
if (element) {
element.addEventListener("click", func(){
console.log("Listener func called");
});
}
}
Executes the given function if the element has the parameter className
.
function onClickMultiple(className, func) {
document.addEventListener('click', function(event) {
if (event.target.classList.contains(className)) {
func(event.target);
}
});
}
Scrolls an element to the bottom.
function scrollToBottom(element) {
element.scrollTop = element.scrollHeight;
}
Redirects your browser to the page
parameter passed.
function redirectTo(page) {
window.location = page;
}
Specify html id
of the element with a #
var element = getElement('#element');
console.log(element);
Specify html id
of the element with a #
var element = getElement('#element');
element.classList.add('className');
console.log("Added " + className);
Specify html id
of the element with a #
var element = getElement('#element');
element.classList.remove('className');
console.log("Removed " + className);
Specify html id
of the element with a #
var element = getElement('#element');
element.setAttribute('key', value);
console.log("Added attribute" + key + ": " + value);