I was reading about bookmarklets and created this for removing elements from a webpage, I got wrote this bookmarklet by reading a few web pages and don't know much about javascript.
javascript: (() => {
const arr = ['div.w3-col', 'div.footer'];
const prop = ['display' 'none', 'important'];
for (let i = 0; i < arr.length; i ) {
document.getElementsByTagName(arr[i])[0].style.setProperty(prop);
}
When I run this in firefox console it gives me following error,
Uncaught SyntaxError: missing ] after element list
note: [ opened at line 3, column 11
What should I do next?
ps I know I can use stylus for this
CodePudding user response:
div.w3-col
is not valid Tag name it css selector, so use below
.querySelectorAll
document.querySelectorAll(arr[i])[0].style.setProperty(prop);
or .querySelector
document.querySelector(arr[i]).style.setProperty(prop);
CodePudding user response:
You forgot a comma between 'display'
and 'none'
.
So, the code should be something like
javascript:(() => {
const arr = ['div.w3-col', 'div.footer'];
const prop = ['display', 'none', 'important'];
for (let i = 0; i < arr.length; i ) {
document.getElementsByTagName(arr[i])[0].style.setProperty(prop);
}
})()