javascript - How to change a style property of element by class name without any use of ID's in JS? -
i doing school project , it's first time using js, , not allowed use id's css styling, on event user want change style of div
in page:
html:
<div class="ads"> ... </div>
css:
.ads{ display:block; //and other style properties }
and when user event want change display property :
display : none;
i know how can done using id element, how can done class name?
i able this:
document.getelementsbyclassname('ads').style.display=none;
thank you.
if know there 1 element class, use first element of nodelist
document.getelementsbyclassname
returns:
document.getelementsbyclassname('ads')[0].style.display = 'none';
Comments
Post a Comment