Hi Team
how do i click button with specific background color using JavaScript?
I cant use functions like getElementsById etc as they dont work for background color
Thanks
B.Singh
Hi Team
how do i click button with specific background color using JavaScript?
I cant use functions like getElementsById etc as they dont work for background color
Thanks
B.Singh
use getComputedStyle function to check different CSS attributes such as height / bg color !!!
function(e){
const elementsWithSpecificBGColor = [];
const elements = document.querySelectorAll("*");
var exist = false
for (let i = 0; i < elements.length; i++) {
const style = getComputedStyle(elements[i]);
if (style.backgroundColor === 'rgb(255, 0, 0)') { // replace 'rgb(255, 0, 0)' with the color you're looking for
//if criteria met, click
elements[i].click();
break;
}
}
Amazing, @jack.chan
const elements = document.querySelectorAll("*");
for this line i dont want to loop all elements, i only want li elements where rel starts with “nofollow”, is that possible
change it to this @bs113256
document.querySelectorAll("li:has([rel^='nofollow']:not([hidden]))")
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.