Zet - How do I dynamically add a css rule to a page using javascript?
How do I dynamically add a css rule to a page using javascript?
Create a style element using document.createElement('style'), set itโs textContext to your css rules, and then append it to the document.head.
eg.
// Create a <style> element
const style = document.createElement('style');
style.textContent = `
div.x1lliihq:has(svg[aria-label="Clip"]) {
display: none;
}
`;
// Append the <style> element to the <body> or <head>
document.head.appendChild(style); // Adds it to <head>
#css #csstricks