Calendar is using 3 different classes to style its child elements: “old day”, “day”, “new day”. Trying to querySelectorAll element with class name “day” also captures the other two classes, so when i say something like:
JavaScript
x
10
10
1
t = document.getElementByTagName('table');
2
d = t.item(0).querySelectorAll('.day');
3
/* also selects td.new.day and td.old.day */
4
5
for (i = 0; i < d.length: i ++) {
6
if(d[i].textContent == 28) {
7
d[i].click();
8
}
9
}
10
I will get click on old 28th instead of current month 28th.
How do i select “day” class of td element without also selecting “old day” and “new day”?
Advertisement
Answer
You can use :not
to specify which classes you don’t want to match.
JavaScript
1
3
1
document.querySelectorAll(".red:not(.big):not(.small)").forEach(e => {
2
e.style.marginLeft = "100px";
3
});
JavaScript
1
3
1
.red {color: red;}
2
.big {font-size: 20px}
3
.small {font-size: 12px}
JavaScript
1
3
1
<a class="red">red</a><br>
2
<a class="red big">red big</a><br>
3
<a class="red small">red small</a>