JS - Grab HTML elements function

PHOTO EMBED

Fri Mar 18 2022 21:59:40 GMT+0000 (Coordinated Universal Time)

Saved by @Chomi #javascript

// Grab elements
//declare function expression, arrow function
//this method helps grab elements very easily
const selectElement = selector => {
    const element = document.querySelector(selector)
    if(element) return element;
    throw new Error('Something went wrong, make sure that ${selector} exists or is typed correctly.');
};

//testing the function
//console.log(selectElement('.footer'));
content_copyCOPY

Freecodecamp blog tutorial

https://youtu.be/Aj7HLsJenVg