How to change style in pure javascript?

2

In jquery:

<script>
$( "#main article:nth-child(3) .postSnippet" ).css("display", "block");
</script>

How would you look in pure JS?

    
asked by anonymous 06.11.2015 / 05:52

1 answer

4

The selector stays the same, what changes is the way to go through the element (s) and apply the desired style. Example:

var e = document.querySelectorAll('#main article:nth-child(3) .postSnippet');
for (var i = 0; i < e.length; i++) {
    e[i].style['display'] = 'block';
}

However, would not it be easier to add a style in your CSS to do this? Example:

 #main article:nth-child(3) .postSnippet {
     display: block;
 }
    
06.11.2015 / 06:39