Detecting element widh DOM javascript -
my question pretty simple, can't detect element, wanna change backgroundcolor through javascript can't check since tag+class + tag+class... here's code tried:
var 1 = document.getelementsbytagname("div"); var 2 = document.getelementsbyclassname("red"); var 3 = document.getelementsbytagname("h2"); var 4 = document.getelementsbyclassname("title"); one.two three.four.style.backgroundcolor ="#00c497";
the format "div.red h2.title". hope me, thanks
if can, use queryselector this:
document.queryselector("div.red h2.title").style.backgroundcolor = "#00c497";
<div> <h2>don't touch</h2> </div> <div class="red"> <h2>don't touch</h2> <h2 class="title">change</h2> </div>
Comments
Post a Comment